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

Incorrect error message when extra whitespace present in tuple return type annotation #6191

Open
masukomi opened this issue Jun 13, 2018 · 3 comments

Comments

@masukomi
Copy link
Contributor

Syntax error in tester.cr:1: unterminated parenthesized expression

def foo(x : String) : Tuple (String, String)
                            ^

This is, hopefully obviously, not an "unterminated parenthesized expression". The parentheses are very much terminated. The consequences of this error are wasting time trying to find a missing ) that isn't missing.

If you remove the space between Tuple and the parens after it the error goes away.

Sample code here

def foo(x : String) : Tuple (String, String)
  {x, x}
end

Tested with

Crystal 0.24.2 (2018-03-10)

LLVM: 5.0.1
Default target: x86_64-apple-macosx
@masukomi masukomi changed the title Incorrect error message when extra whitespace present in tuple return statement Incorrect error message when extra whitespace present in tuple return type annotation Jun 13, 2018
@asterite
Copy link
Member

I'm not sure this is a bug or whether it's worth fixing. This is valid syntax:

def foo : Int32 1 end

After a return type, the only thing that can come (apart from forall) is the method's body. So in your case, after Tuple (after the space) comes the body, which gives you the same syntax error as this:

(String, String)

And that isn't valid Crystal.

@straight-shoota
Copy link
Member

Should def foo : Int32 1 end be valid Crystal? IMHO it looks a bit confusing and I don't know if avoiding a line break adds any value. Why not require a line break (or ;) between the method's signature and body?

@asterite
Copy link
Member

asterite commented Jul 1, 2018

Sure, PRs are welcome.

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

No branches or pull requests

4 participants