-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Proc with Void return type #3655
Comments
Because your block returns |
@ysbaddaden but the following code can be compiled. def foo (&block : Int32 -> Void)
yield 1
end
foo do
1
end |
Right now the compiler, in many places, to determine the type of something, just takes the type on the left-hand side, the type on the right-hand side, combines them, and tries to assign the result to the left-hand side. Here a union is created and it doesn't match the original type. However, since we introduced explicit types in instance variables this rule can be changed or relaxed. In those cases we should try to see if the right-hand side can be implicitly converted to the left-hand side. In the case of a block, it's simpler: if the block specification returns I'll mark this as an enhancement. |
A simple workaround is of course: class A
@@a : String -> Nil
@@a = ->(y : String){
1
nil
}
end |
Could this be bumped? Me and a few others have run into this. It is a bit strange since return types on regular methods set to Also just for clarity to anyone reading this that isn't familiar: def my_method : Nil
"a string"
end Will still compile. This is basically |
PR's are welcome 👍 |
I can try to see if I can merge procs of same argument types and |
compiler complains Proc type doesn't match.
The text was updated successfully, but these errors were encountered: