Skip to content

Commit e623bb1

Browse files
committed
Bugfix: Restore cached denotations of NamedTypes to their value before cc
This is needed to make -Ycheck work after capture checking
1 parent ec019fe commit e623bb1

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,8 @@ object Types {
23482348
lastDenotation match {
23492349
case lastd0: SingleDenotation =>
23502350
val lastd = lastd0.skipRemoved
2351-
if (lastd.validFor.runId == ctx.runId && (checkedPeriod != Nowhere)) finish(lastd.current)
2351+
if lastd.validFor.runId == ctx.runId && checkedPeriod != Nowhere then
2352+
finish(lastd.current)
23522353
else lastd match {
23532354
case lastd: SymDenotation =>
23542355
if (stillValid(lastd) && (checkedPeriod != Nowhere)) finish(lastd.current)
@@ -2453,6 +2454,8 @@ object Types {
24532454
}
24542455

24552456
private def checkDenot()(using Context) = {}
2457+
//if name.toString == "getConstructor" then
2458+
// println(i"set denot of $this to ${denot.info}, ${denot.getClass}, ${Phases.phaseOf(denot.validFor.lastPhaseId)} at ${ctx.phase}")
24562459

24572460
private def checkSymAssign(sym: Symbol)(using Context) = {
24582461
def selfTypeOf(sym: Symbol) =

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ abstract class Recheck extends Phase, SymTransformer:
133133
else sym
134134

135135
def run(using Context): Unit =
136-
newRechecker().checkUnit(ctx.compilationUnit)
136+
val rechecker = newRechecker()
137+
rechecker.checkUnit(ctx.compilationUnit)
138+
rechecker.reset()
137139

138140
def newRechecker()(using Context): Rechecker
139141

@@ -153,6 +155,12 @@ abstract class Recheck extends Phase, SymTransformer:
153155
*/
154156
def keepType(tree: Tree): Boolean = keepAllTypes
155157

158+
private val prevSelDenots = util.HashMap[NamedType, Denotation]()
159+
160+
def reset()(using Context): Unit =
161+
for (ref, mbr) <- prevSelDenots.iterator do
162+
ref.withDenot(mbr)
163+
156164
/** Constant-folded rechecked type `tp` of tree `tree` */
157165
protected def constFold(tree: Tree, tp: Type)(using Context): Type =
158166
val tree1 = tree.withType(tp)
@@ -190,7 +198,16 @@ abstract class Recheck extends Phase, SymTransformer:
190198
qualType.findMember(name, qualType,
191199
excluded = if tree.symbol.is(Private) then EmptyFlags else Private
192200
)).suchThat(tree.symbol == _))
193-
constFold(tree, qualType.select(name, mbr))
201+
val newType = tree.tpe match
202+
case prevType: NamedType =>
203+
val prevDenot = prevType.denot
204+
val newType = qualType.select(name, mbr)
205+
if (newType eq prevType) && (mbr.info ne prevDenot.info) && !prevSelDenots.contains(prevType) then
206+
prevSelDenots(prevType) = prevDenot
207+
newType
208+
case _ =>
209+
qualType.select(name, mbr)
210+
constFold(tree, newType)
194211
//.showing(i"recheck select $qualType . $name : ${mbr.info} = $result")
195212

196213

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class TreeChecker extends Phase with SymTransformer {
9191
if (ctx.phaseId <= erasurePhase.id) {
9292
val initial = symd.initial
9393
assert(symd == initial || symd.signature == initial.signature,
94-
i"""Signature of ${sym.showLocated} changed at phase ${ctx.phase.prevMega}
94+
i"""Signature of ${sym} in ${sym.ownersIterator.toList}%, % changed at phase ${ctx.phase.prevMega}
9595
|Initial info: ${initial.info}
9696
|Initial sig : ${initial.signature}
9797
|Current info: ${symd.info}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package test
2+
3+
import reflect.ClassTag
4+
import language.experimental.pureFunctions
5+
6+
object Settings:
7+
val OptionTag: ClassTag[Option[?]] = ClassTag(classOf[Option[?]])
8+
9+
class Setting[T: ClassTag](propertyClass: Option[Class[?]]):
10+
def tryToSet() =
11+
def update(value: Any): String = ???
12+
implicitly[ClassTag[T]] match
13+
case OptionTag =>
14+
update(Some(propertyClass.get.getConstructor().newInstance()))

0 commit comments

Comments
 (0)