Skip to content

Survive NoType when erasing method result types #15439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i15377.check
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/neg/i15377.scala
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tests/pos/i15377.scala
Original file line number Diff line number Diff line change
@@ -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]