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

Can't use splat generics in Proc type declaration for instance variable #8520

Closed
Blacksmoke16 opened this issue Nov 26, 2019 · 3 comments · Fixed by #10232
Closed

Can't use splat generics in Proc type declaration for instance variable #8520

Blacksmoke16 opened this issue Nov 26, 2019 · 3 comments · Fixed by #10232
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic

Comments

@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Nov 26, 2019

See https://forum.crystal-lang.org/t/splat-generics-with-proc/1410

class Foo(R, *A)
  def initialize(@action : Proc(*A, R)); end
end
 
 
pp Foo(String, Int32, Bool).new ->(a : Int32, b : Bool) { "foo" }

Error:

Error: instance variable '@action' of Foo(String, Int32, Bool) must be Proc(*A, String), not Proc(Int32, Bool, String)
@asterite asterite changed the title Can't use splat generics in Proc type declaration Can't use splat generics in Proc type declaration for instance variable Nov 26, 2019
@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Nov 26, 2019
@Blacksmoke16
Copy link
Member Author

Blacksmoke16 commented Dec 8, 2019

@asterite Do you have any pointers on where to look if I wanted to take a shot at this? My current guess is that the splat arguments need to be "expanded" before seeing if they match or not?

@Blacksmoke16
Copy link
Member Author

Blacksmoke16 commented Dec 8, 2019

Update, this is also an issue when using splat generics as type restriction of a method within Union.

https://play.crystal-lang.org/#/r/85x2

class Foo(*Args)
  def execute(value : Union(*Args))
    pp value
  end
end


foo = Foo(String, Int32).new

foo.execute 19
Showing last frame. Use --error-trace for full trace.

error in line 10
Error: no overload matches 'Foo(String, Int32)#execute' with type Int32

Overloads are:
 - Foo(Args)#execute(value : Union(*Args))

@asterite
Copy link
Member

asterite commented Dec 8, 2019

I think the logic is in restrictions.cr but I'm not sure.

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:compiler:semantic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants