-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #1540: overloaded get and isDefined in option-less patmat #1597
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
Conversation
Block(List(ValDef(b.asTerm, prevValue)), next) | ||
) | ||
val tmpSym = freshSym(prev.pos, prev.tpe, "o") | ||
val prevValue = ref(tmpSym).select(getDenot.namedType).ensureApplied |
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 don't think that can work. getDenot has a type that's dependent on prev
. But the denotation gets added to another prefix, tmpSym
. You could try instead:
ref(tmpSym).select(getDenot.symbol).ensureApplied
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.
Thanks for the tip @odersky !
List(ValDef(tmpSym, prev)), | ||
// must be isEmpty and get as we don't control the target of the call (prev is an extractor call) | ||
ifThenElseZero( | ||
ref(tmpSym).select(isDefinedDenot.namedType), |
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 think you need to do the same as for prevValue here; same reasoning applies.
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.
Thanks for the feedback @odersky , I was wondering why the second succeeded without change. Now I added another test that fails my initial attempt.
LGTM, thanks! |
@@ -240,17 +240,21 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer { | |||
val isDefined = extractorMemberType(prev.tpe, nme.isDefined) | |||
|
|||
if ((isDefined isRef defn.BooleanClass) && getTp.exists) { | |||
val tmpSym = freshSym(prev.pos, prev.tpe, "o") | |||
val prevValue = ref(tmpSym).select("get".toTermName).ensureApplied | |||
// isDefined and get maybe overloaded |
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.
typo: maybe -> may be
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.
Thanks for the catch @smarter , it's fixed in the latest commit.
Fix #1540 .
When
isDefined
andget
are overloaded, make sure the translated code use the correct version of the methods.