Skip to content

Commit 24b63f5

Browse files
committed
Harden GADT constraint handling to survive illegal F-bounds
1 parent ae82716 commit 24b63f5

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ sealed trait GadtState {
193193
case i => pt.paramRefs(i)
194194
case tp => tp
195195
}
196-
196+
if !param.info.exists then
197+
throw TypeError(em"illegal recursive reference involving $param")
197198
val tb = param.info.bounds
198199
tb.derivedTypeBounds(
199200
lo = substDependentSyms(tb.lo, isUpper = false),

tests/neg/i20317.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type Foo[A] = A
2+
3+
def foo[A <: Foo[A]]: Unit = () // error // error

tests/neg/i20317a.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type SemigroupStructural[A] =
2+
A & { def combine(a: A): A }
3+
def combineAll[A <: SemigroupStructural[A]](
4+
i: A, l: List[A]
5+
): A = l.foldLeft(i)(_.combine(_)) // error

0 commit comments

Comments
 (0)