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
Failure to resolve free variables from a method's block return type #12811
Comments
|
One may want to use a class method on a type var before it is solved later by the block, I think it's unexpected that it can't be resolved |
What's sure is that the error can be improved. It's confusing to call a type variable a constant. |
The way the compiler works is like this... if you have a block that says
For example def map(& : T -> U) : Array(U) forall U
ary = [] of U
each { |e| ary << yield e }
ary
end So given
Now let's see the first snippet in this issue: class Foo(T)
def method(&block : U, T -> U) forall U
yield U.zero, T.zero
end
end
Foo(Int32).new.method do |zero, foo|
puts zero, foo
Float64.zero
end Let's try to do the same:
I... I don't think this can be implemented. But let's try it. We have to start by typing something, right? Otherwise it's impossible. Let's try typing the block ( Let's try typing the method. It says I think you are expecting the compiler to somehow only type For this to work the logic of how blocks are typed needs to use bindings, like everywhere else... but that's a bit tricky to implement. In fact I think we didn't do that because there was a blocker I can't remember now.
|
I could grok a bit of that from the semantic visit of |
I think I shouldn't say these things, so I'll never again. What I meant is that I won't do that, but someone might, I don't know. |
The compiler should be able to solve free variables from the return type of a block in cases where the type of other variables can only be deduced from the return type of the block.
Output:
* Failure to solve optional method argument free variable that is not explicitly passed at the call site.
Output:
The text was updated successfully, but these errors were encountered: