-
Notifications
You must be signed in to change notification settings - Fork 5
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
Easy optimization in the pattern match #4
Comments
Also, one question: is the type in |
@jvican, in order to get you |
Great, makes sense! |
I've just pushed a better fix to unsuch branch that generates such code: def getFoodFor(a: Animal): Food & Product0 =
if a.isInstanceOf[Cat] then {
a.asInstanceOf[Cat(c)]
Meat
} else
if a.isInstanceOf[Cow] then {
a.asInstanceOf[Cow(cw)]
Grass
} else throw new MatchError(a) Note that casts are still there as we lack a phase that would know that those casts always succeed. |
Summary of the discussion: mark |
When compiling the code used in #3, we get this (phase simplify):
In this case, the values
c
andcw
could be removed because they are not used at all. Not sure if this is a new optimization target or something that should be fixed in dotty.The text was updated successfully, but these errors were encountered: