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

unexpected ',' in type #6980

Closed
Blacksmoke16 opened this issue Oct 23, 2018 · 5 comments
Closed

unexpected ',' in type #6980

Blacksmoke16 opened this issue Oct 23, 2018 · 5 comments

Comments

@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Oct 23, 2018

module Test
  class Foo; end
  class Bar; end
  
  TYPES = {
    Foo => [] of Symbol,
    Bar => [] of Symbol
  }
end

https://play.crystal-lang.org/#/r/5avh

Syntax error in eval:6: unexpected ',' in type (use parentheses to disambiguate)

Only happens when having the comma on an empty array of T

@asterite
Copy link
Member

asterite commented Oct 23, 2018

You have to do what the error message tells you :-)

module Test
  class Foo; end
  class Bar; end

  TYPES = {
    Foo => ([] of Symbol),
    Bar => ([] of Symbol)
  }
end

The reason of the error is that Symbol, Bar could be the start of a Proc type.

@j8r
Copy link
Contributor

j8r commented Oct 23, 2018

Or use the classic syntax to create a new class instance:

module Test
  class Foo; end
  class Bar; end

  TYPES = {
    Foo => Array(Symbol).new,
    Bar => Array(Symbol).new
  }
end

@Blacksmoke16
Copy link
Member Author

Blacksmoke16 commented Oct 23, 2018

@asterite @j8r Well now the new problem is i get:

undefined macro method 'Call#map'

    CrSerializer::Assertions::NotNil => Array(Symbol).new,

and

undefined macro method 'Expressions#map'

    CrSerializer::Assertions::NotNil => ([] of Symbol),

Since im iterating over the key/values (extra code removed for simplicity), and wanting to map the values in the array. tl;dr of this is im using it to new up classes that correspond with the name of the annotation.

        {% for ivar in @type.instance_vars %}
          {% for t, v in CrSerializer::Assertions::TYPES %}
            {% ann = ivar.annotation(t.resolve) %}
              {% if ann %}
                {{v.map { |f| ann[f] }.join(',').id}}
              {% end %}
          {% end %}
        {% end %}

Ideally this would be a lot cleaner if you could iterate over all the annotations on an ivar, and iterate on keys of the annotation, but that would prob be best for another issue.

@Blacksmoke16
Copy link
Member Author

For now i guess i'll just add a dummy var to the array and just do nothing with it in the initializer.

@Blacksmoke16
Copy link
Member Author

For future reference, solution was to do {% v = v.expressions[0] if v.is_a?(Expressions) %} to get the actual value of the expression if it was one.

@j8r j8r mentioned this issue Feb 6, 2019
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