Skip to content

Conversation

@liufengyun
Copy link
Contributor

Fix #1540 .

When isDefined and get are overloaded, make sure the translated code use the correct version of the methods.

Block(List(ValDef(b.asTerm, prevValue)), next)
)
val tmpSym = freshSym(prev.pos, prev.tpe, "o")
val prevValue = ref(tmpSym).select(getDenot.namedType).ensureApplied
Copy link
Contributor

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

Copy link
Contributor Author

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),
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@odersky
Copy link
Contributor

odersky commented Oct 14, 2016

LGTM, thanks!

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: maybe -> may be

Copy link
Contributor Author

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.

@odersky odersky merged commit 5ebd552 into scala:master Oct 14, 2016
@allanrenucci allanrenucci deleted the fix-i1540 branch December 14, 2017 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants