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
A new variant of #50 (re)surfacing, haven't checked yet among all the original examples, nor if this is fixed by the existing PRs (in particular, #4036). The issue is that (({ type R = A }) & ({ type R = B }))#R is allowed and shouldn't, so I adapted @alexknvl's code in #4060 to implement coerce.
$ dotc -d out UnsoundProj.scala
$ dotr -classpath out AppException in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:101)
at App$.main(UnsoundProj.scala:11)
at App.main(UnsoundProj.scala)
Scala so far allowed general type projection T#A where T is an arbitrary type and A names a type member of T.
Dotty disallows this if T is an abstract type (class types and type aliases are fine). This change was made because unrestricted type projection is unsound.
Projections should be illegal on lots of types T that aren't abstract types themselves — T must be a class type (or alias to such), and A should be a fully defined type member, but type operators like intersections, unions, structural refinements should be forbidden — probably all operators should (unless we have a very good reason for allowing some).
This way, type projections can only access global (type) constants:
classDefining {
typeTypeMember= ...
}
objectDefining {
valvalueMember
}
// Here, Defining#T and Defining.valueMember are both references to known global constants, at value or type-level
The text was updated successfully, but these errors were encountered:
A new variant of #50 (re)surfacing, haven't checked yet among all the original examples, nor if this is fixed by the existing PRs (in particular, #4036). The issue is that
(({ type R = A }) & ({ type R = B }))#R
is allowed and shouldn't, so I adapted @alexknvl's code in #4060 to implementcoerce
.This was prompted by a question from @allanrenucci. He also pointed me to the documentation on type projections (http://dotty.epfl.ch/docs/reference/dropped/type-projection.html), which seems both unclear and misleading:
Projections should be illegal on lots of types
T
that aren't abstract types themselves —T
must be a class type (or alias to such), andA
should be a fully defined type member, but type operators like intersections, unions, structural refinements should be forbidden — probably all operators should (unless we have a very good reason for allowing some).This way, type projections can only access global (type) constants:
The text was updated successfully, but these errors were encountered: