Skip to content

Instantly share code, notes, and snippets.

/tuple_issue.cr Secret

Created February 23, 2018 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/62ecd1b4b7657503d0f418a9ed04f603 to your computer and use it in GitHub Desktop.
Save anonymous/62ecd1b4b7657503d0f418a9ed04f603 to your computer and use it in GitHub Desktop.
A confusing behaviour involving passing a tuple to a constructor without parentheses.
# Simple working example shown below
foo = Foo.new({2, 2})
# ^ ^ Outer parentheses present
class Foo
def initialize(bar : {Int32, Int32})
# Code
end
end
# This, however, will not compile:
foo = Foo.new {2, 2}
# ^ ^ Outer parentheses removed
class Foo
def initialize(bar : {Int32, Int32})
# Code
end
end
# When run, this results in
# unexpected token: ,
# foo = Foo.new { 2, 2 }
# ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment