Skip to content

Commit d90dce2

Browse files
committed
Fix non-termination
The non-termination is caused by typo in the level of `Outer`: it should be `pot.level` instead of `pot.size`.
1 parent 62f03f3 commit d90dce2

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

compiler/src/dotty/tools/dotc/transform/init/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ object Checking {
227227
val cls = denot.symbol.asClass
228228
val potInner =
229229
pot match
230-
case warm: Warm => Warm(cls, pot)(source)
230+
case warm: Warm => Potentials.asSeenFrom(Warm(cls, ThisRef()(source))(source), pot)
231231
case _ => LocalHot(cls)(source)
232232
buffer += MethodCall(potInner, cls.primaryConstructor)(source)
233233
buffer += Promote(potInner)(source)

compiler/src/dotty/tools/dotc/transform/init/Potentials.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ object Potentials {
116116
case class Outer(pot: Potential, classSymbol: ClassSymbol)(val source: Tree) extends Potential {
117117
// be lenient with size of outer selection, no worry for non-termination
118118
override def size: Int = pot.size
119-
override def level: Int = pot.size
119+
override def level: Int = pot.level
120120
def show(using Context): String = pot.show + ".outer[" + classSymbol.show + "]"
121121
}
122122

@@ -125,7 +125,7 @@ object Potentials {
125125
assert(field != NoSymbol)
126126

127127
override def size: Int = potential.size + 1
128-
override def level: Int = potential.size
128+
override def level: Int = potential.level
129129
def show(using Context): String = potential.show + "." + field.name.show
130130
}
131131

@@ -134,7 +134,7 @@ object Potentials {
134134
assert(method != NoSymbol)
135135

136136
override def size: Int = potential.size + 1
137-
override def level: Int = potential.size
137+
override def level: Int = potential.level
138138
def show(using Context): String = potential.show + "." + method.name.show
139139
}
140140

@@ -224,13 +224,11 @@ object Potentials {
224224

225225
case Warm(cls, outer2) =>
226226
// widening to terminate
227-
val thisValue2 = thisValue match {
228-
case Warm(cls, outer) if outer.level > 2 =>
229-
Warm(cls, Cold()(outer2.source))(thisValue.source)
230-
231-
case _ =>
227+
val thisValue2 =
228+
if thisValue.level + outer2.level > 4 then
229+
Cold()(outer2.source)
230+
else
232231
thisValue
233-
}
234232

235233
val outer3 = asSeenFrom(outer2, thisValue2)
236234
Warm(cls, outer3)(pot.source)

tests/init/neg/inner-loop.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Outer { outer =>
22
class Inner extends Outer {
3-
val x = 5 + outer.n
3+
val x = 5 + outer.n // error
44
}
55
val inner = new Inner
66
val n = 6 // error

0 commit comments

Comments
 (0)