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

Type deduction complains about missing Enumerable#each of unrelated class instance #5445

Closed
Papierkorb opened this issue Dec 23, 2017 · 2 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib
Milestone

Comments

@Papierkorb
Copy link
Contributor

Hi,

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

class Foo
  def initialize(@f : Enumerable(String))
    @f.each{ } # ERROR
    # f.each{ } # This is fine.
  end

  def bar; @f.each{ }; end # Same ERROR
end

Foo.new(Dir["*"])

Thanks

@Papierkorb 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
@RX14 RX14 added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib labels Dec 24, 2017
@RX14 RX14 modified the milestones: Next, 0.24.1 Dec 24, 2017
@bcardiff
Copy link
Member

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.

Papierkorb added a commit to Papierkorb/bindgen that referenced this issue Mar 11, 2018
Downside: Bindgen now requires Crystal 0.24.2!
@Papierkorb
Copy link
Contributor Author

A trip-wire in bindgen just notified me indirectly that this issue is now fixed: Papierkorb/qt5.cr#9 per Papierkorb/bindgen@a3c4376

Thanks

@bcardiff bcardiff modified the milestones: 0.25.0, 0.24.2 Jun 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib
Projects
None yet
Development

No branches or pull requests

3 participants