Closed
Description
Compiler version
Scala compiler version 3.0.0-M3
Minimized code
This code is inspired by tests/pos/i4345.scala
.
import scala.annotation.tailrec
class Context {
type Tree
}
final def loop3[C <: Context](): Unit =
@tailrec
def loop4[A <: C](c: A): c.Tree = loop4(c)
Output
-- [E007] Type Mismatch Error: test.scala:19:41 --------------------------------
19 | def loop4[A <: C](c: A): c.Tree = loop4(c)
| ^^^^^^^^
| Found: ?1.Tree
| Required: c.Tree
|
| where: ?1 is an unknown value of type A
1 error found
Result after typer
result of test.scala after typer:
package <empty> {
import scala.annotation.tailrec
class Context() extends Object() {
type Tree >: Nothing <: Any
}
final lazy module val test$package: test$package$ = new test$package$()
final module class test$package$() extends Object() {
this: test$package.type =>
final def loop3[C >: Nothing <: Context](): Unit =
{
@annotation.tailrec() def loop4[A >: Nothing <: C](c: A): c.Tree =
loop4[A](c.$asInstanceOf$[A])
()
}
}
}
Expectation
This code should be compiled but not. c
is converted to c.$asInstanceOf$[A]
in method adapt
when the compiler testSubType
(c:A)
and A
. testSubType
returns OKwithGADTused
, but GADT usage in thirdTryNamed
is unnecessary.