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

[Low Priority] [Error Messages] Suggest case fix when an identifier is typed with the wrong case #9197

Closed
awr1 opened this issue Oct 4, 2018 · 4 comments · Fixed by #16067

Comments

@awr1
Copy link
Contributor

awr1 commented Oct 4, 2018

A small lead-in to the ideas proposed by #3914:

As we all know, Nim uses (non-total) case insensitivity for identifier resolution, and I've noticed a lot of people first getting into Nim don't seem to be aware of the important exception involving the first character of an identifier.

proc foo(x: int) = discard
Foo(3)

will get you the error message

undeclared identifier: 'Foo'

On coming to that error message, it might be helpful if the compiler checks if the normalized identifier validates if the case of the first character is flipped, saying something instead like

undeclared identifier: 'Foo' (Potential first-letter case mismatch: did you mean 'foo'?)

(Of course, the idea eventually for the future would be create a list of approximate identifiers, but, you know, baby steps.)

@narimiran
Copy link
Member

NHF, but even if you (general you) mistakenly think Nim has total case-insensitivity and you declare/call your procs with uppercase first letter, "you gonna have a bad time", and you deserve it by breaking the usual conventions!

What if you had type Foo and proc foo in the same file?

type Foo = object
  a: int

proc foo(a: int): int = 42

let a = Foo(3)

What is the error here? Did you wrongly call your object (should have been let a = Foo(a: 3)) or your function (should have been let a = foo(3))?

@awr1
Copy link
Contributor Author

awr1 commented Oct 6, 2018

Well, like I said, eventually the best thing to do would be to have a list of possible calls you meant to use (which would likely include object ctors). But for this issue specifically I was thinking of just procedure calls. (I admit sometimes I will get confused of whether or not I'm using the right case when it comes to say, bindings to a library that uses PascalCase for procedures - did whoever implement the bindings change these to camelCase? Granted, this is a not a huge deal and it is very easy to come to whichever is the correct form. I'm just spit-balling things that I think will help newbies.)

Calling Foo() there directs to a different error path: Error: type mismatch: got <int literal(3)> but expected 'Foo = object'. It could be helpful to provide correct ctor syntax here, especially if the parameters appear to typecheck in the right order in relation to the order of the (accessible) fields as defined in the object.

@narimiran
Copy link
Member

I've been going through the old issues, and it seems there was a similar issue opened 3 years ago: #2844.

Should this be closed as a duplicate?

@dom96
Copy link
Contributor

dom96 commented Oct 8, 2018

Yes, duplicate.

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