From ccd71bb0ffcc640574695e0c58e3e56d750172bd Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 1 Jun 2021 11:37:49 +0200 Subject: [PATCH] Harden type comparer in presence of kind errors It should not crash when an override has the wrong kind. Fixes #12664 --- .../src/dotty/tools/dotc/core/TypeComparer.scala | 2 +- tests/neg/i12664.scala | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i12664.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 47f36255de81..7c7aba8a95b0 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -1422,7 +1422,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling def recurArgs(args1: List[Type], args2: List[Type], tparams2: List[ParamInfo]): Boolean = if (args1.isEmpty) args2.isEmpty - else args2.nonEmpty && { + else args2.nonEmpty && tparams2.nonEmpty && { val tparam = tparams2.head val v = tparam.paramVarianceSign diff --git a/tests/neg/i12664.scala b/tests/neg/i12664.scala new file mode 100644 index 000000000000..5e4b784475aa --- /dev/null +++ b/tests/neg/i12664.scala @@ -0,0 +1,14 @@ +trait Step { + type Self + type Next[A] +} + +trait DynamicNextStep { + type OneOf[Self, Next[_]] + def apply(s: Step): OneOf[s.Self, s.Next] +} + +object X extends DynamicNextStep { + override type OneOf[Self] = Self // error + override def apply(s: Step) = ??? +}