Skip to content

Commit ed65987

Browse files
committed
Survive NoType when erasing method result types
Fixes #15377
1 parent 836ed97 commit ed65987

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
138138
* `refedInnerClasses` may contain duplicates, need not contain the enclosing inner classes of
139139
* each inner class it lists (those are looked up and included).
140140
*
141-
* This method serializes in the InnerClasses JVM attribute in an appropriate order,
141+
* This method serializes in the InnerClasses JVM attribute in an appropriate order,
142142
* not necessarily that given by `refedInnerClasses`.
143143
*
144144
* can-multi-thread

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
638638
eraseResult(tp.resultType) match {
639639
case rt: MethodType =>
640640
tp.derivedLambdaType(names ++ rt.paramNames, formals ++ rt.paramInfos, rt.resultType)
641+
case NoType =>
642+
// Can happen if we smuggle in a Nothing in the qualifier. Normally we prevent that
643+
// in Checking.checkMembersOK, but compiler-generated code can bypass this test.
644+
// See i15377.scala for a test case.
645+
NoType
641646
case rt =>
642647
tp.derivedLambdaType(names, formals, rt)
643648
}

tests/neg/i15377.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg/i15377.scala:11:6 ----------------------------------------------------------------------------------
2+
11 | def func(a: A) = a // error
3+
| ^^^^^^^^^^^^^^^^^^
4+
| a.A is not defined in inferred type a.A

tests/neg/i15377.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
trait WithPath:
3+
type A
4+
5+
trait Proto:
6+
type A <: WithPath
7+
def func(a: A): a.A
8+
9+
object Impl extends Proto:
10+
type A = Nothing
11+
def func(a: A) = a // error

tests/pos/i15377.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trait Tst:
2+
val a: Int
3+
4+
trait Q[A <: Tst]:
5+
def mk(a: A): a.a.type = a.a
6+
7+
object Q extends Q[Nothing]

0 commit comments

Comments
 (0)