aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/core/Types.scala3
-rw-r--r--src/dotty/tools/dotc/transform/Literalize.scala10
2 files changed, 8 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 0e9f5d9b2..5fd3b81d0 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -94,9 +94,8 @@ object Types {
/** Does this type denote a stable reference (i.e. singleton type)? */
final def isStable(implicit ctx: Context): Boolean = stripTypeVar match {
case tp: TermRef => tp.termSymbol.isStable && tp.prefix.isStable
- case _: SingletonType => true
+ case _: SingletonType | NoPrefix => true
case tp: RefinedType => tp.parent.isStable
- case NoPrefix => true
case _ => false
}
diff --git a/src/dotty/tools/dotc/transform/Literalize.scala b/src/dotty/tools/dotc/transform/Literalize.scala
index 4a223e912..f33baa52b 100644
--- a/src/dotty/tools/dotc/transform/Literalize.scala
+++ b/src/dotty/tools/dotc/transform/Literalize.scala
@@ -51,9 +51,13 @@ class Literalize extends MiniPhaseTransform { thisTransform =>
* Revisit this issue once we have implemented `inline`. Then we can demand
* purity of the prefix unless the selection goes to an inline val.
*/
- def literalize(tree: Tree)(implicit ctx: Context): Tree = tree.tpe match {
- case ConstantType(value) if isIdempotentExpr(tree) => Literal(value)
- case _ => tree
+ def literalize(tree: Tree)(implicit ctx: Context): Tree = {
+ def recur(tp: Type): Tree = tp match {
+ case ConstantType(value) if isIdempotentExpr(tree) => Literal(value)
+ case tp: TermRef if tp.symbol.isStable => recur(tp.info.widenExpr)
+ case _ => tree
+ }
+ recur(tree.tpe)
}
override def transformIdent(tree: Ident)(implicit ctx: Context, info: TransformerInfo): Tree =