Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tc-env-lookup-value: suggest type constructors #1097

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jbouwman
Copy link
Contributor

On variable lookup miss, existing suggestion code has no effect because it looks at the two places just checked. Instead check the environment to see if the var names a type, meaning, maybe the user was looking for a type constructor.

Closes #1095

On variable lookup miss, existing suggestion code has no effect
because it looks at the two places just checked. Instead check the
environment to see if the var names a type, meaning, maybe the user
was looking for a type constructor.
Copy link
Member

@stylewarning stylewarning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love this kind of usability enhancement. just some bitty things

src/typechecker/tc-env.lisp Outdated Show resolved Hide resolved
src/typechecker/tc-env.lisp Outdated Show resolved Hide resolved
src/typechecker/tc-env.lisp Outdated Show resolved Hide resolved
Copy link
Member

@stylewarning stylewarning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, would like @eliaslfox to peek too

@@ -4,6 +4,7 @@
#:coalton-impl/typechecker/base
#:coalton-impl/typechecker/parse-type)
(:local-nicknames
(#:a #:alexandria)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't PLN alexandria.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll accept the PLN

(#:the-library-of-alexandria #:alexandria)

however. send tweet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a compromise, it could be referred to via the Mongolian vowel separator jbouwman#2

"Look up a type binding of VAR-NAME in type checker environment ENV."
(gethash var-name (tc-env-ty-table env)))

(defun lookup-var (env var-name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't define this function.

@@ -47,57 +48,59 @@

(tc:qualified-ty-type (tc:fresh-inst (setf (gethash name (tc-env-ty-table env)) (tc:to-scheme (tc:make-variable))))))

(defun lookup-var-type (env var-name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't define this function.

(push (apply #'format nil fmt-string fmt-args) suggestions)))

;; If the symbol names a type, user may have intended to use a type constructor
(a:when-let ((type (tc:lookup-type (tc-env-env env) var-name :no-error t)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use when-let

(defun tc-env-suggest-value (env var-name)
"If value lookup failed, generate suggestions for what to do, if anything."
(let ((suggestions nil))
(flet ((suggest (fmt-string &rest fmt-args)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just write this inline.

"Look up a variable binding of VAR-NAME in type checker environment ENV."
(tc:lookup-value-type (tc-env-env env) var-name :no-error t))

(defun tc-env-suggest-value (env var-name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add type annotations to this function.

;; including checking other places in the environment and
;; catching simple spelling errors.

)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paren goes on line 67

(defun tc-env-lookup-value (env var file)
"Lookup a variable named VAR in ENV."
"Lookup the value of a variable named VAR in ENV."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the type of

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using Type name instead of constructor returns opaque unknown variable error
3 participants