Skip to content

Fix #10116: Fix adaptConstant to that it survives Ycheck #10280

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

Merged
merged 2 commits into from
Nov 11, 2020

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Nov 11, 2020

No description provided.

@odersky odersky requested a review from sjrd November 11, 2020 10:15
@@ -3425,7 +3425,7 @@ class Typer extends Namer
// try converting a constant to the target type
val folded = ConstFold(tree, pt)
if (folded ne tree)
return adaptConstant(folded, folded.tpe.asInstanceOf[ConstantType])
return adaptConstant(tree, folded.tpe.asInstanceOf[ConstantType])
Copy link
Member

Choose a reason for hiding this comment

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

Hum. Looking at this fix and at ConstFold.apply(tree, pt), I think the latter basically produces an invalid tree, that is never safe to reuse.

I also see that ConstFold.Apply(tree, pt) is used only here. With the fix, we are therefore patching the invalid result of ConstFold.apply at its only call site; but if someone starts calling that overload somewhere else, they will likely reintroduce a similar bug.

Consider inlining the contents of that overload of ConstFold(tree, tp) here instead. Once you do that, you won't have to create that transient invalid tree, since you'll be able to directly use x.convertTo(tp) instead of folded.tpe.

This would prevent further invalid uses of that overload.

@odersky odersky merged commit 2788c99 into scala:master Nov 11, 2020
@odersky odersky deleted the fix-#10116 branch November 11, 2020 14:59
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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.

3 participants