-
-
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
Interpreter: fix 12351 #12374
Interpreter: fix 12351 #12374
Conversation
It would be great to merge #12355 so that we can easily see if this caused any regressions :-) |
# Make sure to always cast the argument to the target def arg's type | ||
cast = Cast.new(var, TypeNode.new(target_def_arg.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.
Just wondering, could we skip this cast if arg type and target type are identical?
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.
That's true!
I'm now thinking that we only need the cast in the last if
, where there's no restriction on the argument. Because otherwise the arg's type is always checked. Let me try it...
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.
Done!
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.
To expand a bit more on this: a multidispatch will generate code like this:
def multidispatch(arg)
if arg.is_a?(String)
foo(arg)
elsif arg.is_a?(Int32)
foo(arg)
else
foo(arg)
end
end
In this case if arg
's type is String | Int32 | Nil
the last branch will have arg
's type to be Nil
. But, the method corresponding to foo
might either take Nil
or maybe String | Nil
, or even String | Int32 | Nil
depending on how the overloads are defined.
To make the cast conditionally on the last branch we'd have to know what the type of arg
is there: removing any types that were already checked in .is_a?
. Given that this is an optimization, I'd like to leave it for later or maybe not even implement it later (at most we just have one Cast node that does nothing)
Is it okay to merge this even if the Windows build is failing? |
Yeah, that's probably just a hiccup. |
It seems like this PR introduced a bug. The interpreter failed to run the std specs. |
Fixes #12351