Skip to content
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

Backport "Fix validity period of derived SingleDenotations" to LTS #21026

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,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

Expand Down Expand Up @@ -1153,11 +1153,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(
Expand All @@ -1168,15 +1168,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
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1618,11 +1618,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(
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,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
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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.*
Expand Down Expand Up @@ -131,7 +132,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))
}
Expand Down
17 changes: 17 additions & 0 deletions compiler/test-resources/repl/i18756
Original file line number Diff line number Diff line change
@@ -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