From c544e4128931bba8650bd61d2d29131f75426ccb Mon Sep 17 00:00:00 2001 From: odersky Date: Thu, 2 May 2024 13:23:31 +0200 Subject: [PATCH 1/2] Harden GADT constraint handling to survive illegal F-bounds --- compiler/src/dotty/tools/dotc/core/GadtConstraint.scala | 3 ++- tests/neg/i20317.scala | 3 +++ tests/neg/i20317a.scala | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i20317.scala create mode 100644 tests/neg/i20317a.scala diff --git a/compiler/src/dotty/tools/dotc/core/GadtConstraint.scala b/compiler/src/dotty/tools/dotc/core/GadtConstraint.scala index 1cbfabc08958..5a8938602523 100644 --- a/compiler/src/dotty/tools/dotc/core/GadtConstraint.scala +++ b/compiler/src/dotty/tools/dotc/core/GadtConstraint.scala @@ -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), diff --git a/tests/neg/i20317.scala b/tests/neg/i20317.scala new file mode 100644 index 000000000000..e9d8599b9fc1 --- /dev/null +++ b/tests/neg/i20317.scala @@ -0,0 +1,3 @@ +type Foo[A] = A + +def foo[A <: Foo[A]]: Unit = () // error // error diff --git a/tests/neg/i20317a.scala b/tests/neg/i20317a.scala new file mode 100644 index 000000000000..d7b8b66eb80e --- /dev/null +++ b/tests/neg/i20317a.scala @@ -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 From 5e408bdf2e9c6b326398d27e6f682187e8db708f Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 6 May 2024 12:48:45 +0200 Subject: [PATCH 2/2] Add test to best effort blacklist --- compiler/test/dotc/neg-best-effort-pickling.blacklist | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/test/dotc/neg-best-effort-pickling.blacklist b/compiler/test/dotc/neg-best-effort-pickling.blacklist index ff02be107a8a..1c8421b44539 100644 --- a/compiler/test/dotc/neg-best-effort-pickling.blacklist +++ b/compiler/test/dotc/neg-best-effort-pickling.blacklist @@ -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