-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix constant conversion to singleton types #12212
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package dotty.tools.dotc | ||
package dotty.tools | ||
package dotc | ||
package core | ||
|
||
import Types._, Symbols._, Contexts._ | ||
import printing.Printer | ||
import printing.Texts.Text | ||
import Decorators._ | ||
|
||
object Constants { | ||
|
||
|
@@ -161,25 +163,29 @@ object Constants { | |
} | ||
case pt => pt | ||
} | ||
val target = classBound(pt).typeSymbol | ||
if (target == tpe.typeSymbol) | ||
this | ||
else if ((target == defn.ByteClass) && isByteRange) | ||
Constant(byteValue) | ||
else if (target == defn.ShortClass && isShortRange) | ||
Constant(shortValue) | ||
else if (target == defn.CharClass && isCharRange) | ||
Constant(charValue) | ||
else if (target == defn.IntClass && isIntRange) | ||
Constant(intValue) | ||
else if (target == defn.LongClass && isLongRange) | ||
Constant(longValue) | ||
else if (target == defn.FloatClass && isFloatRange) | ||
Constant(floatValue) | ||
else if (target == defn.DoubleClass && isNumeric) | ||
Constant(doubleValue) | ||
else | ||
null | ||
pt match | ||
case ConstantType(value) if value == this => this | ||
case _: SingletonType => null | ||
case _ => | ||
val target = classBound(pt).typeSymbol | ||
if (target == tpe.typeSymbol) | ||
this | ||
else if ((target == defn.ByteClass) && isByteRange) | ||
Constant(byteValue) | ||
else if (target == defn.ShortClass && isShortRange) | ||
Constant(shortValue) | ||
else if (target == defn.CharClass && isCharRange) | ||
Constant(charValue) | ||
else if (target == defn.IntClass && isIntRange) | ||
Constant(intValue) | ||
else if (target == defn.LongClass && isLongRange) | ||
Constant(longValue) | ||
else if (target == defn.FloatClass && isFloatRange) | ||
Constant(floatValue) | ||
else if (target == defn.DoubleClass && isNumeric) | ||
Constant(doubleValue) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a series of
Noticed the similar pattern in constant folding. Maybe nbd for 7 tests. My question would be what should my fingers type automatically for this pattern. It could optimize |
||
else | ||
null | ||
} | ||
|
||
def stringValue: String = value.toString | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
val pi: 3.14 = 3 // error |
Uh oh!
There was an error while loading. Please reload this page.