Skip to content

Commit 59f208b

Browse files
committed
restrict isRefinedMethod to JointRefDenotation
1 parent bcde8c4 commit 59f208b

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
@@ -1115,7 +1115,7 @@ object Denotations {
11151115
}
11161116
}
11171117

1118-
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type, override val prefix: Type, override val isRefinedMethod: Boolean) extends SingleDenotation(symbol, initInfo) {
1118+
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type, override val prefix: Type) extends SingleDenotation(symbol, initInfo) {
11191119
def infoOrCompleter: Type = initInfo
11201120
def isType: Boolean = infoOrCompleter.isInstanceOf[TypeType]
11211121
}
@@ -1124,27 +1124,29 @@ object Denotations {
11241124
symbol: Symbol,
11251125
initInfo: Type,
11261126
initValidFor: Period,
1127-
prefix: Type,
1128-
isRefinedMethod: Boolean) extends NonSymSingleDenotation(symbol, initInfo, prefix, isRefinedMethod) {
1127+
prefix: Type) extends NonSymSingleDenotation(symbol, initInfo, prefix) {
11291128
validFor = initValidFor
11301129
override def hasUniqueSym: Boolean = true
11311130
protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean): SingleDenotation =
1132-
new UniqueRefDenotation(s, i, validFor, pre, isRefinedMethod)
1131+
if isRefinedMethod then
1132+
new JointRefDenotation(s, i, validFor, pre, isRefinedMethod)
1133+
else
1134+
new UniqueRefDenotation(s, i, validFor, pre)
11331135
}
11341136

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

1147-
class ErrorDenotation(using Context) extends NonSymSingleDenotation(NoSymbol, NoType, NoType, false) {
1149+
class ErrorDenotation(using Context) extends NonSymSingleDenotation(NoSymbol, NoType, NoType) {
11481150
override def exists: Boolean = false
11491151
override def hasUniqueSym: Boolean = false
11501152
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
@@ -1499,7 +1499,10 @@ object SymDenotations {
14991499
// ----- copies and transforms ----------------------------------------
15001500

15011501
protected def newLikeThis(s: Symbol, i: Type, pre: Type, isRefinedMethod: Boolean): SingleDenotation =
1502-
new UniqueRefDenotation(s, i, validFor, pre, isRefinedMethod)
1502+
if isRefinedMethod then
1503+
new JointRefDenotation(s, i, validFor, pre, isRefinedMethod)
1504+
else
1505+
new UniqueRefDenotation(s, i, validFor, pre)
15031506

15041507
/** Copy this denotation, overriding selective fields */
15051508
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
@@ -751,15 +751,16 @@ object Types {
751751
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
752752
}
753753
else
754+
val isRefinedMethod = rinfo.isInstanceOf[MethodOrPoly]
754755
val joint = pdenot.meet(
755-
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre, isRefinedMethod = false),
756+
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre, isRefinedMethod),
756757
pre,
757758
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
758759
joint match
759760
case joint: SingleDenotation
760-
if rinfo.isInstanceOf[MethodOrPoly] && rinfo <:< joint.info =>
761+
if isRefinedMethod && rinfo <:< joint.info =>
761762
// use `rinfo` to keep the right parameter names for named args. See i8516.scala.
762-
joint.derivedSingleDenotation(joint.symbol, rinfo, isRefinedMethod = true)
763+
joint.derivedSingleDenotation(joint.symbol, rinfo, pre, isRefinedMethod)
763764
case _ =>
764765
joint
765766
}
@@ -809,7 +810,7 @@ object Types {
809810
def goSuper(tp: SuperType) = go(tp.underlying) match {
810811
case d: JointRefDenotation =>
811812
typr.println(i"redirecting super.$name from $tp to ${d.symbol.showLocated}")
812-
new UniqueRefDenotation(d.symbol, tp.memberInfo(d.symbol), d.validFor, pre, isRefinedMethod = false)
813+
new UniqueRefDenotation(d.symbol, tp.memberInfo(d.symbol), d.validFor, pre)
813814
case d => d
814815
}
815816

@@ -4697,7 +4698,7 @@ object Types {
46974698
// also other information about the named type (e.g. bounds).
46984699
contains(
46994700
TypeRef(tp.prefix, cls)
4700-
.withDenot(new UniqueRefDenotation(cls, tp, cls.validFor, tp.prefix, isRefinedMethod = false)))
4701+
.withDenot(new UniqueRefDenotation(cls, tp, cls.validFor, tp.prefix)))
47014702
case _ =>
47024703
lo <:< tp && tp <:< hi
47034704
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class Erasure extends Phase with DenotTransformer {
113113
}
114114
case ref: JointRefDenotation =>
115115
new UniqueRefDenotation(
116-
ref.symbol, transformInfo(ref.symbol, ref.symbol.info), ref.validFor, ref.prefix, ref.isRefinedMethod)
116+
ref.symbol, transformInfo(ref.symbol, ref.symbol.info), ref.validFor, ref.prefix)
117117
case _ =>
118118
ref.derivedSingleDenotation(ref.symbol, transformInfo(ref.symbol, ref.symbol.info))
119119
}

0 commit comments

Comments
 (0)