Skip to content

Unhelpful error message (Error: unexpected token: "(") when defining method that starts with a capital letter. #15316

@Zopolis4

Description

@Zopolis4

Bug Report

The following code fails to compile:

def Foo(bar)
 puts "qux #{bar}"
end

Foo("quux")

with the following error:

In temp.cr:1:8

 1 | def Foo(bar)
            ^
Error: unexpected token: "("

I believe the starting with the capital letter is the issue, because renaming the method to foo or fFoo or _Foo fixed it (successfully printing the output of qux quux), but the error message does not make that clear.

I was additionally unable to find any documentation detailing that method names couldn't start with capital letters, so assuming I am not incorrect about the cause of the error it may help to update the relevant documentation to take note of that in addition to updating the error message.

Tested on:

Crystal 1.14.0 [dacd97bcc] (2024-10-09)

LLVM: 18.1.6
Default target: x86_64-unknown-linux-gnu

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugA bug in the code. Does not apply to documentation, specs, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions