Skip to content

Commit 24d3219

Browse files
committed
Show root of stackoverflow in IsFullyDefinedAccumulator
This gives a better diagnsosis for #12640.
1 parent 89e57aa commit 24d3219

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -167,33 +167,36 @@ object Inferencing {
167167

168168
private var toMaximize: List[TypeVar] = Nil
169169

170-
def apply(x: Boolean, tp: Type): Boolean = tp.dealias match {
171-
case _: WildcardType | _: ProtoType =>
172-
false
173-
case tvar: TypeVar if !tvar.isInstantiated =>
174-
force.appliesTo(tvar)
175-
&& ctx.typerState.constraint.contains(tvar)
176-
&& {
177-
val direction = instDirection(tvar.origin)
178-
if minimizeSelected then
179-
if direction <= 0 && tvar.hasNonWildcardLowerBound then
170+
def apply(x: Boolean, tp: Type): Boolean =
171+
try tp.dealias match
172+
case _: WildcardType | _: ProtoType =>
173+
false
174+
case tvar: TypeVar if !tvar.isInstantiated =>
175+
force.appliesTo(tvar)
176+
&& ctx.typerState.constraint.contains(tvar)
177+
&& {
178+
val direction = instDirection(tvar.origin)
179+
if minimizeSelected then
180+
if direction <= 0 && tvar.hasNonWildcardLowerBound then
181+
instantiate(tvar, fromBelow = true)
182+
else if direction >= 0 && tvar.hasNonWildcardUpperBound then
183+
instantiate(tvar, fromBelow = false)
184+
// else hold off instantiating unbounded unconstrained variable
185+
else if direction != 0 then
186+
instantiate(tvar, fromBelow = direction < 0)
187+
else if variance >= 0 && (force.ifBottom == IfBottom.ok || tvar.hasLowerBound) then
180188
instantiate(tvar, fromBelow = true)
181-
else if direction >= 0 && tvar.hasNonWildcardUpperBound then
182-
instantiate(tvar, fromBelow = false)
183-
// else hold off instantiating unbounded unconstrained variable
184-
else if direction != 0 then
185-
instantiate(tvar, fromBelow = direction < 0)
186-
else if variance >= 0 && (force.ifBottom == IfBottom.ok || tvar.hasLowerBound) then
187-
instantiate(tvar, fromBelow = true)
188-
else if variance >= 0 && force.ifBottom == IfBottom.fail then
189-
return false
190-
else
191-
toMaximize = tvar :: toMaximize
192-
foldOver(x, tvar)
193-
}
194-
case tp =>
195-
foldOver(x, tp)
196-
}
189+
else if variance >= 0 && force.ifBottom == IfBottom.fail then
190+
return false
191+
else
192+
toMaximize = tvar :: toMaximize
193+
foldOver(x, tvar)
194+
}
195+
case tp =>
196+
foldOver(x, tp)
197+
catch case ex: Throwable =>
198+
handleRecursive("traverse ", s"${tp.show}" , ex)
199+
197200

198201
def process(tp: Type): Boolean =
199202
// Maximize type vars in the order they were visited before */

tests/neg/i12640.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package x
2+
3+
trait CpsMonad[F[_]]:
4+
def pure[A](x:A): F[A]
5+
def flatMap[A,B](fa:F[A])(f: A=>F[B]): F[B]
6+
7+
abstract sealed class CpsStream[-F[_],+T]
8+
9+
case class Cons[F[_],T](head:T, tailFun: ()=>F[CpsStream[F,T]]) extends CpsStream[F,T]
10+
11+
case class Empty[F[_]]() extends CpsStream[F,Nothing]
12+
13+
def unfold[S,F[_]:CpsMonad,T](s0:S)(f:S => F[Option[(S,T)]]):F[CpsStream[F,T]] =
14+
summon[CpsMonad[F]].flatMap(f(s0)){
15+
case Some(s1,a) => Cons(a, () => unfold(s1,f))
16+
case None => summon[CpsMonad[F]].pure(Empty[F]())
17+
}

0 commit comments

Comments
 (0)