Crystal: Incorrect error message when extra whitespace present in tuple return type annotation

Created on 13 Jun 2018  路  3Comments  路  Source: crystal-lang/crystal

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
bug discussion topicparser

Most helpful comment

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?

All 3 comments

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.

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?

Sure, PRs are welcome.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asterite picture asterite  路  60Comments

xtagon picture xtagon  路  132Comments

akzhan picture akzhan  路  67Comments

stugol picture stugol  路  70Comments

malte-v picture malte-v  路  77Comments