Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 408d9f3

Browse files
committedApr 23, 2025
Erase all covariant and invariant into occurrences
Erase all covariant and invariant into occurrences in parameter types
1 parent e6a2f35 commit 408d9f3

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed
 

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

+16-16
Original file line numberDiff line numberDiff line change
@@ -939,25 +939,25 @@ object TypeOps:
939939

940940
/** Map no-flip covariant occurrences of `into[T]` to `T @$into` */
941941
def suppressInto(using Context) = new FollowAliasesMap:
942-
def apply(t: Type): Type =
943-
if variance <= 0 then t
944-
else t match
945-
case AppliedType(tycon: TypeRef, arg :: Nil) if defn.isInto(tycon.symbol) =>
946-
AnnotatedType(arg, Annotation(defn.SilentIntoAnnot, util.Spans.NoSpan))
947-
case _ =>
948-
mapFollowingAliases(t)
942+
def apply(t: Type): Type = t match
943+
case AppliedType(tycon: TypeRef, arg :: Nil) if variance >= 0 && defn.isInto(tycon.symbol) =>
944+
AnnotatedType(arg, Annotation(defn.SilentIntoAnnot, util.Spans.NoSpan))
945+
case _: MatchType | _: LazyRef =>
946+
t
947+
case _ =>
948+
mapFollowingAliases(t)
949949

950950
/** Map no-flip covariant occurrences of `T @$into` to `into[T]` */
951951
def revealInto(using Context) = new FollowAliasesMap:
952-
def apply(t: Type): Type =
953-
if variance <= 0 then t
954-
else t match
955-
case AnnotatedType(t1, ann) if ann.symbol == defn.SilentIntoAnnot =>
956-
AppliedType(
957-
defn.ConversionModule.termRef.select(defn.Conversion_into), // the external reference to the opaque type
958-
t1 :: Nil)
959-
case _ =>
960-
mapFollowingAliases(t)
952+
def apply(t: Type): Type = t match
953+
case AnnotatedType(t1, ann) if variance >= 0 && ann.symbol == defn.SilentIntoAnnot =>
954+
AppliedType(
955+
defn.ConversionModule.termRef.select(defn.Conversion_into), // the external reference to the opaque type
956+
t1 :: Nil)
957+
case _: MatchType | _: LazyRef =>
958+
t
959+
case _ =>
960+
mapFollowingAliases(t)
961961

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

‎docs/_docs/reference/experimental/into.md

+2-1
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)
Please sign in to comment.