这是我的问题的最小再现:
trait Superclass[T]
class A(val key: Any) extends Superclass[key.type]
val x: Superclass["123"] = A("123")
如您所见,我正在尝试将 Key 的静态已知类型编码到类型参数中。这不像我可以将类型key
作为 A 的类型参数,因为在我的真实示例中,它更像,class A(using g: blablah)(val key: g.Key) extends SuperClass[g.Mapping[key.type]]
但这与上述问题无关。
只是我们不能在超类的参数中使用依赖类型吗?
更新
类型成员的编码产生相同的错误:
trait Superclass {
type T
}
class A(val key: Any) extends Superclass {
type T = key.type
}
val x: Superclass & {type T = "123"} = A("123")
我仍然得到
[error] 14 | val x: Superclass & {type T = "123"} = A("123")
[error] | ^^^^^^^^
[error] | Found: Main.A
[error] | Required: Main.Superclass & Object{T = ("123" : String)}