Skip to content

Commit

Permalink
Harden GADT constraint handling to survive illegal F-bounds (#20325)
Browse files Browse the repository at this point in the history
This currently fails BestEffortCompilationTests

The problem is that i20317a.scala contains illegal cyclic references.
The cycles cause many different algorithms in the compiler to loop. We
normally reject the program, and that's that. But under best-effort, we
crash with Stackoverflows in the loops later. What to do? It's not
feasible to avoid the looping behavior at acceptable cost. Can we
disable best effort under certain conditions?
  • Loading branch information
odersky authored May 7, 2024
2 parents 1f3c652 + 5e408bd commit 44c1e3a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/GadtConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ sealed trait GadtState {
case i => pt.paramRefs(i)
case tp => tp
}

if !param.info.exists then
throw TypeError(em"illegal recursive reference involving $param")
val tb = param.info.bounds
tb.derivedTypeBounds(
lo = substDependentSyms(tb.lo, isUpper = false),
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/neg-best-effort-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ curried-dependent-ift.scala
i17121.scala
illegal-match-types.scala
i13780-1.scala
i20317a.scala

# semantic db generation fails in the first compilation
i1642.scala
Expand Down
3 changes: 3 additions & 0 deletions tests/neg/i20317.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type Foo[A] = A

def foo[A <: Foo[A]]: Unit = () // error // error
5 changes: 5 additions & 0 deletions tests/neg/i20317a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type SemigroupStructural[A] =
A & { def combine(a: A): A }
def combineAll[A <: SemigroupStructural[A]](
i: A, l: List[A]
): A = l.foldLeft(i)(_.combine(_)) // error

0 comments on commit 44c1e3a

Please sign in to comment.