Closed
Description
Compiler version
3.3.1-RC1 (on current main)
Minimized code
Command:
run path/to/file.scala -Xprint:typer
File:
import scala.annotation.Annotation
class myAnnot[T]() extends Annotation
trait Tensor[T]:
def add: Tensor[T] @myAnnot[T]()
class TensorImpl[A]() extends Tensor[A]:
def add = this
See also example below without subtyping or inference
Output
[[syntax trees at end of typer]] // path/to/file.scala
package <empty> {
import scala.annotation.Annotation
class myAnnot[T >: Nothing <: Any]() extends scala.annotation.Annotation() {
T
}
trait Tensor[T >: Nothing <: Any]() extends Object {
T
def add: Tensor[Tensor.this.T] @myAnnot[T]
}
class TensorImpl[A >: Nothing <: Any]() extends Object(), Tensor[
TensorImpl.this.A] {
A
def add: Tensor[A] @myAnnot[T] = this // This T refers to the parent trait's T !
}
}
Expectation
[[syntax trees at end of typer]] // path/to/file.scala
package <empty> {
import scala.annotation.Annotation
class myAnnot[T >: Nothing <: Any]() extends scala.annotation.Annotation() {
T
}
trait Tensor[T >: Nothing <: Any]() extends Object {
T
def add: Tensor[Tensor.this.T] @myAnnot[T]
}
class TensorImpl[A >: Nothing <: Any]() extends Object(), Tensor[
TensorImpl.this.A] {
A
def add: Tensor[A] @myAnnot[A] = this // Only change
}
}