You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have this code that works fine on Crystal 1.1.1, but on 1.2.0 I get a compile-time error
Showing last frame. Use --error-trace for full trace.
error in line 23
Error: undefined method 'name' for Reference (compile-time type is Object+)
I know there's some weirdness around using Object so generically, so in this case, changing it to Enumerable(Thing) fixes the error. However, my actual app is a bit more complicated of a fix.
classThingproperty name : Stringdefinitialize(@name : String)
endendclassDecoratorincludeEnumerable(Object)
definitialize(@things : Array(Thing))
enddefeach@things.each do |t|
yield t
endendend
dec =Decorator.new([Thing.new("foo")])
pp dec.find {|t| t.name =="foo" }
I'm ok with closing this out if this is intended, but I wanted to make sure it was at least reported just in case.
The text was updated successfully, but these errors were encountered:
I'd definitely say there are some weird things about this.
For example, I don't know how Enumerable(Object) was even working. I'd expected some error such as can't use Object as generic type argument or can't use Object as a Proc argument type. Both should be triggered by Enumerable(Object).
i believe generic modules are allowed to use type arguments that aren't usable as the type of a variable; for example Comparable(Array) is okay, even though a variable cannot have the type Array, because Comparable(T) only uses T in non-block parameter restrictions.
Enumerable(Object) indeed should still be disallowed because of #each(& : T ->). It is by sheer coincidence the code worked before 1.2.0, and methods that return an Array(T) would still break.
I have this code that works fine on Crystal 1.1.1, but on 1.2.0 I get a compile-time error
I know there's some weirdness around using
Object
so generically, so in this case, changing it toEnumerable(Thing)
fixes the error. However, my actual app is a bit more complicated of a fix.I'm ok with closing this out if this is intended, but I wanted to make sure it was at least reported just in case.
The text was updated successfully, but these errors were encountered: