diff options
author | Martin Odersky <odersky@gmail.com> | 2015-08-23 23:09:53 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-08-23 23:10:01 +0200 |
commit | 5b454b1070c3018203263f3bda21db217ed84f3f (patch) | |
tree | b78860de7d685397273922979f8c256f830b353d /src | |
parent | 5710272caea25014ac36517543a85f07c5f801d1 (diff) | |
download | dotty-5b454b1070c3018203263f3bda21db217ed84f3f.tar.gz dotty-5b454b1070c3018203263f3bda21db217ed84f3f.tar.bz2 dotty-5b454b1070c3018203263f3bda21db217ed84f3f.zip |
Make literalize work for TermRefs of constant type.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 3 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/Literalize.scala | 10 |
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 = |