You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classRef[-T]
sealedtraitOpcaseclassSend[T](ref: Ref[T], msg: T) extendsOpobjectMain {
valref:Ref[String] =???valop:Op=Send(ref, "hello")
op match {
caseSend(ref, msg) =>
}
}
Compiling this with dotty 0.1.2-RC1 yields:
[warn] -- Warning: /Users/rkuhn/comp/test/dotty/dotty-project-template/src/main/scala/Main.scala:10:13
[warn] 10 | case Send(target, msg) =>
[warn] | ^^^^^^^^^^^^^^^^^
[warn] | There is no best instantiation of pattern type Send[Any^]
[warn] | that makes it a subtype of selector type Op.
[warn] | Non-variant type variable T cannot be uniquely instantiated.
[warn] | (This would be an error under strict mode)
[warn] one warning found
The important knowledge encapsulated by the Send type is that it has been constructed with ref and msg matching each other. When pattern matching on such a type, I don’t care what the type parameter was, I only care that it was the same for the ref and the msg. Why can’t dotty just make up a type parameter that is not bound and use that in the case statement?
The text was updated successfully, but these errors were encountered:
Indeed, that works, as does case s: Send[t]. This begs the question as to why the warning/error is raised: clearly there is a way to express “some instantiation of T” within dotty’s type system.
In non-variant contexts, we used to always maximize them, but this is unsound.
See neg/patternUnsoundness.scala. We now create fresh abstract types in
these situations.
Consider the following example:
Compiling this with dotty 0.1.2-RC1 yields:
The important knowledge encapsulated by the
Send
type is that it has been constructed with ref and msg matching each other. When pattern matching on such a type, I don’t care what the type parameter was, I only care that it was the same for the ref and the msg. Why can’t dotty just make up a type parameter that is not bound and use that in the case statement?The text was updated successfully, but these errors were encountered: