diff --git a/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala b/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala index 83b25f47f79b..b6d898b3b221 100644 --- a/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala +++ b/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala @@ -138,7 +138,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters { * `refedInnerClasses` may contain duplicates, need not contain the enclosing inner classes of * each inner class it lists (those are looked up and included). * - * This method serializes in the InnerClasses JVM attribute in an appropriate order, + * This method serializes in the InnerClasses JVM attribute in an appropriate order, * not necessarily that given by `refedInnerClasses`. * * can-multi-thread diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index cb9874070456..6e7bb0e7a0d4 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -638,6 +638,11 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst eraseResult(tp.resultType) match { case rt: MethodType => tp.derivedLambdaType(names ++ rt.paramNames, formals ++ rt.paramInfos, rt.resultType) + case NoType => + // Can happen if we smuggle in a Nothing in the qualifier. Normally we prevent that + // in Checking.checkMembersOK, but compiler-generated code can bypass this test. + // See i15377.scala for a test case. + NoType case rt => tp.derivedLambdaType(names, formals, rt) } diff --git a/tests/neg/i15377.check b/tests/neg/i15377.check new file mode 100644 index 000000000000..aca67ddd316c --- /dev/null +++ b/tests/neg/i15377.check @@ -0,0 +1,4 @@ +-- Error: tests/neg/i15377.scala:11:6 ---------------------------------------------------------------------------------- +11 | def func(a: A) = a // error + | ^^^^^^^^^^^^^^^^^^ + | a.A is not defined in inferred type a.A diff --git a/tests/neg/i15377.scala b/tests/neg/i15377.scala new file mode 100644 index 000000000000..a3a0f478cfc1 --- /dev/null +++ b/tests/neg/i15377.scala @@ -0,0 +1,11 @@ + +trait WithPath: + type A + +trait Proto: + type A <: WithPath + def func(a: A): a.A + +object Impl extends Proto: + type A = Nothing + def func(a: A) = a // error \ No newline at end of file diff --git a/tests/pos/i15377.scala b/tests/pos/i15377.scala new file mode 100644 index 000000000000..3fbf4296c6f3 --- /dev/null +++ b/tests/pos/i15377.scala @@ -0,0 +1,7 @@ +trait Tst: + val a: Int + +trait Q[A <: Tst]: + def mk(a: A): a.a.type = a.a + +object Q extends Q[Nothing]