-
-
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
Compiler: let Proc(T) pass a restriction of Proc(Nil) #8969
Conversation
# If checking the return type, any type matches Nil | ||
if i == other.type_vars.size - 1 && nil_type?(other_type_var, context) | ||
# Also, all other types matched, so the matching type is this proc type | ||
# except that it has a Nil return type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the proc were honoring subtyping of arrow types.
It is safe for the following example to compile.
class Foo
end
class Bar < Foo
end
def foo(x : Proc(Bar, Nil))
x
end
a = 1
proc = foo(->(b : Foo) { a = 2 })
r = proc.call(Bar.new)
It is subject for a later change, but is the subtying of arrow type in procs that we are missing it seems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we need to make subtyping work, but it won't work all of the time: only for class references. For structs it's not possible because the representation is different. Also for unions, I think. So for now I didn't implement it until we think it well. But matching against Nil
is more common and easier to check.
I won't merge any more PRs because I don't know whether they should be in 0.34.0 or later. |
I think this is safe to fit into 0.34 since it's handling more cases without loosing or changing others. On my end, feel free to merge it if you want. |
Thanks @asterite! |
Fixes #8964