Skip to content

Commit 7713419

Browse files
committed
restrict isRefinedMethod to JointRefDenotation
1 parent 0a0997a commit 7713419

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ object Denotations {
477477
val jointInfo = infoMeet(info1, info2, safeIntersection)
478478
if jointInfo.exists then
479479
val sym = if symScore >= 0 then sym1 else sym2
480-
JointRefDenotation(sym, jointInfo, denot1.validFor & denot2.validFor, pre, denot1.isRefinedMethod && denot2.isRefinedMethod)
480+
JointRefDenotation(sym, jointInfo, denot1.validFor & denot2.validFor, pre, denot1.isRefinedMethod || denot2.isRefinedMethod)
481481
else if symScore == 2 then denot1
482482
else if symScore == -2 then denot2
483483
else
@@ -1117,7 +1117,7 @@ object Denotations {
11171117
}
11181118
}
11191119

1120-
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type, override val prefix: Type, override val isRefinedMethod: Boolean) extends SingleDenotation(symbol, initInfo) {
1120+
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type, override val prefix: Type) extends SingleDenotation(symbol, initInfo) {
11211121
def infoOrCompleter: Type = initInfo
11221122
def isType: Boolean = infoOrCompleter.isInstanceOf[TypeType]
11231123
}
@@ -1126,27 +1126,29 @@ object Denotations {
11261126
symbol: Symbol,
11271127
initInfo: Type,
11281128
initValidFor: Period,
1129-
prefix: Type,
1130-
isRefinedMethod: Boolean) extends NonSymSingleDenotation(symbol, initInfo, prefix, isRefinedMethod) {
1129+
prefix: Type) extends NonSymSingleDenotation(symbol, initInfo, prefix) {
11311130
validFor = initValidFor
11321131
override def hasUniqueSym: Boolean = true
11331132
protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean): SingleDenotation =
1134-
new UniqueRefDenotation(s, i, validFor, pre, isRefinedMethod)
1133+
if isRefinedMethod then
1134+
new JointRefDenotation(s, i, validFor, pre, isRefinedMethod)
1135+
else
1136+
new UniqueRefDenotation(s, i, validFor, pre)
11351137
}
11361138

11371139
class JointRefDenotation(
11381140
symbol: Symbol,
11391141
initInfo: Type,
11401142
initValidFor: Period,
11411143
prefix: Type,
1142-
isRefinedMethod: Boolean) extends NonSymSingleDenotation(symbol, initInfo, prefix, isRefinedMethod) {
1144+
override val isRefinedMethod: Boolean) extends NonSymSingleDenotation(symbol, initInfo, prefix) {
11431145
validFor = initValidFor
11441146
override def hasUniqueSym: Boolean = false
11451147
protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean): SingleDenotation =
11461148
new JointRefDenotation(s, i, validFor, pre, isRefinedMethod)
11471149
}
11481150

1149-
class ErrorDenotation(using Context) extends NonSymSingleDenotation(NoSymbol, NoType, NoType, false) {
1151+
class ErrorDenotation(using Context) extends NonSymSingleDenotation(NoSymbol, NoType, NoType) {
11501152
override def exists: Boolean = false
11511153
override def hasUniqueSym: Boolean = false
11521154
validFor = Period.allInRun(ctx.runId)

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,10 @@ object SymDenotations {
15051505
// ----- copies and transforms ----------------------------------------
15061506

15071507
protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean): SingleDenotation =
1508-
new UniqueRefDenotation(s, i, validFor, pre, isRefinedMethod)
1508+
if isRefinedMethod then
1509+
new JointRefDenotation(s, i, validFor, pre, isRefinedMethod)
1510+
else
1511+
new UniqueRefDenotation(s, i, validFor, pre)
15091512

15101513
/** Copy this denotation, overriding selective fields */
15111514
final def copySymDenotation(

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,15 +772,16 @@ object Types {
772772
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
773773
}
774774
else
775+
val isRefinedMethod = rinfo.isInstanceOf[MethodOrPoly]
775776
val joint = pdenot.meet(
776-
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre, isRefinedMethod = false),
777+
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre, isRefinedMethod),
777778
pre,
778779
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
779780
joint match
780781
case joint: SingleDenotation
781-
if rinfo.isInstanceOf[MethodOrPoly] && rinfo <:< joint.info =>
782+
if isRefinedMethod && rinfo <:< joint.info =>
782783
// use `rinfo` to keep the right parameter names for named args. See i8516.scala.
783-
joint.derivedSingleDenotation(joint.symbol, rinfo, isRefinedMethod = true)
784+
joint.derivedSingleDenotation(joint.symbol, rinfo, pre, isRefinedMethod)
784785
case _ =>
785786
joint
786787
}
@@ -830,7 +831,7 @@ object Types {
830831
def goSuper(tp: SuperType) = go(tp.underlying) match {
831832
case d: JointRefDenotation =>
832833
typr.println(i"redirecting super.$name from $tp to ${d.symbol.showLocated}")
833-
new UniqueRefDenotation(d.symbol, tp.memberInfo(d.symbol), d.validFor, pre, isRefinedMethod = false)
834+
new UniqueRefDenotation(d.symbol, tp.memberInfo(d.symbol), d.validFor, pre)
834835
case d => d
835836
}
836837

@@ -4711,7 +4712,7 @@ object Types {
47114712
// also other information about the named type (e.g. bounds).
47124713
contains(
47134714
TypeRef(tp.prefix, cls)
4714-
.withDenot(new UniqueRefDenotation(cls, tp, cls.validFor, tp.prefix, isRefinedMethod = false)))
4715+
.withDenot(new UniqueRefDenotation(cls, tp, cls.validFor, tp.prefix)))
47154716
case _ =>
47164717
lo <:< tp && tp <:< hi
47174718
}

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class Erasure extends Phase with DenotTransformer {
120120
}
121121
case ref: JointRefDenotation =>
122122
new UniqueRefDenotation(
123-
ref.symbol, transformInfo(ref.symbol, ref.symbol.info), ref.validFor, ref.prefix, ref.isRefinedMethod)
123+
ref.symbol, transformInfo(ref.symbol, ref.symbol.info), ref.validFor, ref.prefix)
124124
case _ =>
125125
ref.derivedSingleDenotation(ref.symbol, transformInfo(ref.symbol, ref.symbol.info))
126126
}

0 commit comments

Comments
 (0)