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
In my code, I do a globbing lookup akin to Dir[*some_usergiven_patterns]. The method this Dir returns is restricted to Array(String) as result type, which works great with being Dir.[] : Array(String) too.
Now, I have a class further down which accepts and stores an Enumerable(String) in an instance variable. This enumerable happens to be generated by said method above. For some reason, the Crystal compiler complains that abstract 'def Enumerable(T)#each(&block)' must be implemented by Dir.
This worked fine in Crystal versions before 0.24.x. Also, the compiler is correct: Dir#each(&blk) is indeed missing, and this should be fixed. Maybe by Dir not being an Enumerable(String) itself. However, the compiler shouldn't complain in any case, as I never pass around an instance of Dir.
Example snippet
classFoodefinitialize(@f : Enumerable(String))
@f.each{ } # ERROR# f.each{ } # This is fine.enddefbar; @f.each{ }; end# Same ERRORendFoo.new(Dir["*"])
Thanks
The text was updated successfully, but these errors were encountered:
Papierkorb
changed the title
Type deduction comaplins about missing Enumerable#each of unrelated class instance
Type deduction complains about missing Enumerable#each of unrelated class instance
Dec 23, 2017
Note that although this occur in Dir, the underlying limitation of the compiler is that the compiler is not enforcing that abstract methods of generic modules are implemented.
The compiler does check for the implementation of abstract method of non generic modules though.
Hi,
In my code, I do a globbing lookup akin to
Dir[*some_usergiven_patterns]
. The method this Dir returns is restricted toArray(String)
as result type, which works great with beingDir.[] : Array(String)
too.Now, I have a class further down which accepts and stores an
Enumerable(String)
in an instance variable. This enumerable happens to be generated by said method above. For some reason, the Crystal compiler complains thatabstract 'def Enumerable(T)#each(&block)' must be implemented by Dir
.This worked fine in Crystal versions before
0.24.x
. Also, the compiler is correct:Dir#each(&blk)
is indeed missing, and this should be fixed. Maybe byDir
not being anEnumerable(String)
itself. However, the compiler shouldn't complain in any case, as I never pass around an instance ofDir
.Example snippet
Thanks
The text was updated successfully, but these errors were encountered: