Skip to content

Commit 935e8d1

Browse files
committed
Erase all covariant and invariant into occurrences
Erase all covariant and invariant into occurrences in parameter types
1 parent 3ad6fe0 commit 935e8d1

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -947,25 +947,25 @@ object TypeOps:
947947

948948
/** Map no-flip covariant occurrences of `into[T]` to `T @$into` */
949949
def suppressInto(using Context) = new FollowAliasesMap:
950-
def apply(t: Type): Type =
951-
if variance <= 0 then t
952-
else t match
953-
case AppliedType(tycon: TypeRef, arg :: Nil) if defn.isInto(tycon.symbol) =>
954-
AnnotatedType(arg, Annotation(defn.SilentIntoAnnot, util.Spans.NoSpan))
955-
case _ =>
956-
mapFollowingAliases(t)
950+
def apply(t: Type): Type = t match
951+
case AppliedType(tycon: TypeRef, arg :: Nil) if variance >= 0 && defn.isInto(tycon.symbol) =>
952+
AnnotatedType(arg, Annotation(defn.SilentIntoAnnot, util.Spans.NoSpan))
953+
case _: MatchType | _: LazyRef =>
954+
t
955+
case _ =>
956+
mapFollowingAliases(t)
957957

958958
/** Map no-flip covariant occurrences of `T @$into` to `into[T]` */
959959
def revealInto(using Context) = new FollowAliasesMap:
960-
def apply(t: Type): Type =
961-
if variance <= 0 then t
962-
else t match
963-
case AnnotatedType(t1, ann) if ann.symbol == defn.SilentIntoAnnot =>
964-
AppliedType(
965-
defn.ConversionModule.termRef.select(defn.Conversion_into), // the external reference to the opaque type
966-
t1 :: Nil)
967-
case _ =>
968-
mapFollowingAliases(t)
960+
def apply(t: Type): Type = t match
961+
case AnnotatedType(t1, ann) if variance >= 0 && ann.symbol == defn.SilentIntoAnnot =>
962+
AppliedType(
963+
defn.ConversionModule.termRef.select(defn.Conversion_into), // the external reference to the opaque type
964+
t1 :: Nil)
965+
case _: MatchType | _: LazyRef =>
966+
t
967+
case _ =>
968+
mapFollowingAliases(t)
969969

970970
/** Apply [[Type.stripTypeVar]] recursively. */
971971
def stripTypeVars(tp: Type)(using Context): Type =

docs/_docs/reference/experimental/into.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ as they are seen in a method body. Here is an example:
121121
```
122122
Inside the `++` method, the `elems` parameter is of type `IterableOnce[A]`, not `into[IterableOne[A]]`. Hence, we can simply write `elems.iterator` to get at the `iterator` method of the `IterableOnce` class.
123123

124-
Specifically (meaning in spec-language): We erase all `into` wrappers in the local types of parameter types, on the top-level of these types as well as in all _top-level covariant_ subparts. Here, a part `S` of a type `T` is top-level covariant it is not enclosed in some type that appears in contra-variant or invariant position in `T`.
124+
Specifically, we erase all `into` wrappers in the local types of parameter types that appear in covariant or invariant position. Contravariant `into` wrappers are kept since these typically are on the parameters of function arguments.
125+
125126

126127
## Into in Aliases
127128

0 commit comments

Comments
 (0)