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

reserved keywords error messages #6042

Closed
c1tt1 opened this issue May 1, 2018 · 4 comments
Closed

reserved keywords error messages #6042

c1tt1 opened this issue May 1, 2018 · 4 comments

Comments

@c1tt1
Copy link

c1tt1 commented May 1, 2018

A similar issue was raised in #4121

It would be good to produce proper error messages for using reserved keywords in the language.
The below example shows I am using the out keyword.

def foo(up : String, down : String, out : String)
  bar = JSON.build do |json|
    json.object do
      json.field "up", up
      json.field "down", down
      json.field "out", out
    end
  end

  bar
end

The compiler throw the following error at compile time. Same with crystal tool format.

Syntax Error: can't use variable name 'bar' inside assignment to variable 'bar'

The above message gives no idea about out been a reserved keyword and suggests bar is.
Displaying proper errors for builtin types would be good.

  • Crystal compiler version Crystal 0.24.2 (2018-03-10) LLVM: 5.0.1
  • OS x86_64-apple-macosx
@straight-shoota
Copy link
Member

straight-shoota commented May 1, 2018

Reduced example:

def foo(out : String)
  bar = begin
    puts out
  end
  bar # can't use variable name 'bar' inside assignment to variable 'bar'
end

I initially expected this to be resolved by #5930, but out was not considered to be in the list of disallowed argument names.

Still, there seems to be some issue with it. It would be easy to simply restrict the use of out as argument name, but it is usually not an issue because it doesn't have any special meaning outside of argument definitions and there it's usage should be unambiguous.
This seems really odd, as if local var out was confused with bar when used as a method argument, but the syntax error happens in a seemingly unconnected line.

@c1tt1
Copy link
Author

c1tt1 commented May 1, 2018

#5930 was merged 18 days ago which means it will be available on next release correct?

@Sija
Copy link
Contributor

Sija commented May 1, 2018

@stern0 it's correct (unless core team decides to release half-baked version like 0.24.2 was).

@straight-shoota
Copy link
Member

@stern0 #5930 doesn't fix this.

esse added a commit to esse/crystal that referenced this issue May 2, 2018
esse added a commit to esse/crystal that referenced this issue May 2, 2018
chris-huxtable pushed a commit to chris-huxtable/crystal that referenced this issue Jun 6, 2018
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

No branches or pull requests

3 participants