diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index bd92fa814a6e..350823420e66 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -580,7 +580,7 @@ object Denotations { /** A non-overloaded denotation */ abstract class SingleDenotation(symbol: Symbol, initInfo: Type, isType: Boolean) extends Denotation(symbol, initInfo, isType) { - protected def newLikeThis(symbol: Symbol, info: Type, pre: Type, isRefinedMethod: Boolean): SingleDenotation + protected def newLikeThis(symbol: Symbol, info: Type, pre: Type, isRefinedMethod: Boolean)(using Context): SingleDenotation final def name(using Context): Name = symbol.name @@ -1104,7 +1104,9 @@ object Denotations { && (derivedInfo eq info) && !needsPrefix then this else - derivedSingleDenotation(symbol, derivedInfo, pre) + val d = derivedSingleDenotation(symbol, derivedInfo, pre) + d.validFor = currentStablePeriod + d end derived // Tt could happen that we see the symbol with prefix `this` as a member a different class @@ -1162,11 +1164,11 @@ object Denotations { prefix: Type) extends NonSymSingleDenotation(symbol, initInfo, prefix) { validFor = initValidFor override def hasUniqueSym: Boolean = true - protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean): SingleDenotation = + protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean)(using Context): SingleDenotation = if isRefinedMethod then - new JointRefDenotation(s, i, validFor, pre, isRefinedMethod) + new JointRefDenotation(s, i, currentStablePeriod, pre, isRefinedMethod) else - new UniqueRefDenotation(s, i, validFor, pre) + new UniqueRefDenotation(s, i, currentStablePeriod, pre) } class JointRefDenotation( @@ -1177,15 +1179,15 @@ object Denotations { override val isRefinedMethod: Boolean) extends NonSymSingleDenotation(symbol, initInfo, prefix) { validFor = initValidFor override def hasUniqueSym: Boolean = false - protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean): SingleDenotation = - new JointRefDenotation(s, i, validFor, pre, isRefinedMethod) + protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean)(using Context): SingleDenotation = + new JointRefDenotation(s, i, currentStablePeriod, pre, isRefinedMethod) } class ErrorDenotation(using Context) extends NonSymSingleDenotation(NoSymbol, NoType, NoType) { override def exists: Boolean = false override def hasUniqueSym: Boolean = false validFor = Period.allInRun(ctx.runId) - protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean): SingleDenotation = + protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean)(using Context): SingleDenotation = this } diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index b3fe5757720e..7985f21ccab3 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1624,11 +1624,11 @@ object SymDenotations { // ----- copies and transforms ---------------------------------------- - protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean): SingleDenotation = + protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean)(using Context): SingleDenotation = if isRefinedMethod then - new JointRefDenotation(s, i, validFor, pre, isRefinedMethod) + new JointRefDenotation(s, i, currentStablePeriod, pre, isRefinedMethod) else - new UniqueRefDenotation(s, i, validFor, pre) + new UniqueRefDenotation(s, i, currentStablePeriod, pre) /** Copy this denotation, overriding selective fields */ final def copySymDenotation( diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index e38fbbb4b355..4e374831a961 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -905,7 +905,7 @@ object Types extends TypeUtils { def goSuper(tp: SuperType) = go(tp.underlying) match { case d: JointRefDenotation => typr.println(i"redirecting super.$name from $tp to ${d.symbol.showLocated}") - new UniqueRefDenotation(d.symbol, tp.memberInfo(d.symbol), d.validFor, pre) + new UniqueRefDenotation(d.symbol, tp.memberInfo(d.symbol), currentStablePeriod, pre) case d => d } diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala index 9fdffb0ed537..01fc423b0076 100644 --- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala +++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala @@ -13,6 +13,7 @@ import core.Types.* import core.Names.* import core.StdNames.* import core.NameOps.* +import core.Periods.currentStablePeriod import core.NameKinds.{AdaptedClosureName, BodyRetainerName, DirectMethName} import core.Scopes.newScopeWith import core.Decorators.* @@ -132,7 +133,7 @@ class Erasure extends Phase with DenotTransformer { } case ref: JointRefDenotation => new UniqueRefDenotation( - ref.symbol, transformInfo(ref.symbol, ref.symbol.info), ref.validFor, ref.prefix) + ref.symbol, transformInfo(ref.symbol, ref.symbol.info), currentStablePeriod, ref.prefix) case _ => ref.derivedSingleDenotation(ref.symbol, transformInfo(ref.symbol, ref.symbol.info)) } diff --git a/compiler/test-resources/repl/i18756 b/compiler/test-resources/repl/i18756 new file mode 100644 index 000000000000..56be353e67f3 --- /dev/null +++ b/compiler/test-resources/repl/i18756 @@ -0,0 +1,17 @@ +scala> object A { val f: ( => Int) => Int = i => i ; f(1) } +// defined object A + +scala> A.f(1) +val res0: Int = 1 + +scala> A.f(1) +val res1: Int = 1 + +scala> object B { val f: ( => Int) => Int = i => i ; f(1) } +// defined object B + +scala> B.f(1) +val res2: Int = 1 + +scala> B.f(1) +val res3: Int = 1