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

Support "can't infer type parameter" error for uninstantiated generic modules #11904

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Mar 16, 2022

This snippet:

class Foo(T)
  def self.foo(&block : T -> )
    block
  end
end

Foo.foo { |x| } # Error: can't infer the type parameter T for the generic class Foo(T). Please provide it explicitly

produces a less specific error undefined constant T if Foo were a generic module instead. This PR changes that.

The same will also apply if T is used in foo's body:

module Foo(T)
  def self.foo
    T.bar
  end
end

Foo.foo # Error: can't infer the type parameter T for the generic module Foo(T). Please provide it explicitly

For classes this often happens with code like Array.new.

Copy link
Member

@beta-ziliani beta-ziliani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@beta-ziliani beta-ziliani added this to the 1.4.0 milestone Mar 18, 2022
@straight-shoota straight-shoota merged commit a24621f into crystal-lang:master Mar 20, 2022
@HertzDevil HertzDevil deleted the feature/generic-module-cant-infer branch March 21, 2022 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants