-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Erase constant value type [ci: last-only] #9431
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
base: 2.13.x
Are you sure you want to change the base?
Conversation
Quick lunchtime fix. This probably breaks overriding a method of literal type. (Edit: that works after all. I was wondering about the asymmetry of the fix.) |
@som-snytt is this one you're thinking of reviving...? |
@SethTisue yes, although like all old relationships, I've forgotten what was so attractive about it. |
The bug fix is to handle The rest of the commit is style adjustments while reading code. It is difficult to see the history above, but the first swing was about matching members; lrytz hinted it's just an erasure problem; and at some point I made that tweak. A duplicate ticket from a decade ago shows that the symptom has been noticed for some time; that ticket said specialized, so may have been neglected on that basis; it is unknown whether mysterious runtime errors were due to this behavior; OTOH, how often does one override with a constant result. Edit: maybe this was what gave me pause:
Edit: that was constructors detecting whether to drop RHS, resulting in abstract member. |
Ran the sbt test locally, thanks to instructions in build.sbt.
It's supposed to recompile and notice B.y is now a String. From the test name, it looks like erroring was the old behavior. Or is it supposed to be skipped as "pending" not "test"? What's going on? (That is, I have to learn something new again?) All the PENDING are failures. |
The repording for those pending tests is very confusing :-/
is its way of saying "I ran So the scripted tests look clean. The real error seems to be
|
D'oh, I didn't scroll back far enough. It's so hard to keep up with these important computering skills. |
The other important skill is when the comment says "special case", to preserve the special case. My other style preference that has evolved is to avoid long lines where the important bit is pushed too far to the right. Less important side effects can be pushed right, speaking typographically not politically. Then vertical alignment becomes a matter of aligning important bits, as we learned when writing out addition with a pencil. |
NoSymbol | ||
) | ||
final def overridingSymbol(ofclazz: Symbol): Symbol = | ||
if (canMatchInheritedSymbols) matchingSymbol(ofclazz, ofclazz.thisType) else NoSymbol |
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.
One-liner has the same form as previous method; this works well because the else alternative is trivial.
@@ -609,7 +607,7 @@ abstract class Constructors extends Statics with Transform with TypingTransforme | |||
|
|||
private def triage() = { | |||
// Constant typed vals are not memoized. | |||
def memoizeValue(sym: Symbol) = !sym.info.resultType.isInstanceOf[FoldableConstantType] | |||
def memoizeValue(sym: Symbol) = enteringErasure(!sym.info.resultType.isInstanceOf[FoldableConstantType]) |
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.
Why it's important to study history.
deriveDefDef(stat)(_ => EmptyTree) | ||
} | ||
else dd | ||
defBuf += toMove |
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 used to think vertical boolean exprs (wrapped in parens) were too much style just to have leading infix operators, but after using actual leading infix (without parens), I find it much easier to read. I only preferred the one-liner because mentally I would skip it and that's why it felt easier to read.
note that under -Xsource:3
we could be using leading infix.
if (ct.tag == ClazzTag) | ||
if (ct.typeValue.typeSymbol == UnitClass) tp | ||
else ConstantType(Constant(apply(ct.typeValue))) | ||
else ct.tpe |
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.
The fix for erasure. There are really 2 special cases under Class
constant. Presumably the Unit
case is handled specially later, but from this perspective, the encoding doesn't look regular.
Mixin was confused when
String("hello, world")
overridesString
.Fixes scala/bug#12301