diff options
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r-- | src/dotty/tools/dotc/core/Substituters.scala | 10 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 17 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/PlainPrinter.scala | 2 |
3 files changed, 22 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/core/Substituters.scala b/src/dotty/tools/dotc/core/Substituters.scala index c67d352a4..a7977dc2b 100644 --- a/src/dotty/tools/dotc/core/Substituters.scala +++ b/src/dotty/tools/dotc/core/Substituters.scala @@ -12,7 +12,7 @@ trait Substituters { this: Context => case tp: BoundType => if (tp.binder eq from) tp.copyBoundType(to.asInstanceOf[tp.BT]) else tp case tp: NamedType => - if (tp.denotationIsCurrent && tp.symbol.isStatic) tp + if (tp.currentSymbol.isStatic) tp else tp.derivedSelect(subst(tp.prefix, from, to, theMap)) case _: ThisType | NoPrefix => tp @@ -166,7 +166,7 @@ trait Substituters { this: Context => case tp: ThisType => if (tp.cls eq from) to else tp case tp: NamedType => - if (tp.symbol.isStaticOwner) tp + if (tp.currentSymbol.isStaticOwner) tp else tp.derivedSelect(substThis(tp.prefix, from, to, theMap)) case _: BoundType | NoPrefix => tp @@ -184,7 +184,7 @@ trait Substituters { this: Context => case tp @ RefinedThis(rt) => if (rt eq from) to else tp case tp: NamedType => - if (tp.denotationIsCurrent && tp.symbol.isStatic) tp + if (tp.currentSymbol.isStatic) tp else tp.derivedSelect(substThis(tp.prefix, from, to, theMap)) case _: ThisType | _: BoundType | NoPrefix => tp @@ -202,7 +202,7 @@ trait Substituters { this: Context => case tp: BoundType => if (tp == from) to else tp case tp: NamedType => - if (tp.symbol.isStatic) tp + if (tp.currentSymbol.isStatic) tp else tp.derivedSelect(substParam(tp.prefix, from, to, theMap)) case _: ThisType | NoPrefix => tp @@ -220,7 +220,7 @@ trait Substituters { this: Context => case tp: ParamType => if (tp.binder == from) to(tp.paramNum) else tp case tp: NamedType => - if (tp.symbol.isStatic) tp + if (tp.currentSymbol.isStatic) tp else tp.derivedSelect(substParams(tp.prefix, from, to, theMap)) case _: ThisType | NoPrefix | _: RefinedThis => tp diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index c2d465f7f..42ff62f4d 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -1102,9 +1102,24 @@ object Types { // (1) checkedPeriod != Nowhere => lastDenotation != null // (2) lastDenotation != null => lastSymbol != null + /** There is a denotation computed which is valid (somewhere in) the + * current run. + */ def denotationIsCurrent(implicit ctx: Context) = lastDenotation != null && lastDenotation.validFor.runId == ctx.runId + /** The the denotation is current, its symbol, otherwise NoDenotation. + * + * Note: This operation does not force the denotation, and is therefore + * timing dependent. It should only be used if the outcome of the + * essential computation does not depend on the symbol being present or not. + * It's currently used to take an optimized path in substituters and + * type accumulators, as well as to be safe in diagnostiic printing. + * Normally, it's better to use `symbol`, not `currentSymbol`. + */ + def currentSymbol(implicit ctx: Context) = + if (denotationIsCurrent) symbol else NoSymbol + /** The denotation currently denoted by this type */ final def denot(implicit ctx: Context): Denotation = { val now = ctx.period @@ -2659,7 +2674,7 @@ object Types { this(x, if (tp1.exists) tp1 else tp.prefix) } case tp: TermRef => - if (stopAtStatic && tp.denotationIsCurrent && tp.symbol.isStatic) x + if (stopAtStatic && tp.currentSymbol.isStatic) x else this(x, tp.prefix) case _: ThisType diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala index 7a2b93178..9fba7ec09 100644 --- a/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -182,7 +182,7 @@ class PlainPrinter(_ctx: Context) extends Printer { text.stripPrefix(objectPrefix).stripPrefix(packagePrefix) protected def selectionString(tp: NamedType) = - if (tp.denotationIsCurrent && tp.symbol.exists) nameString(tp.symbol) + if (tp.currentSymbol.exists) nameString(tp.symbol) else nameString(tp.name) /** The string representation of this type used as a prefix */ |