Skip to content

Commit fe470c4

Browse files
committed
Adapt reduction of applications to new scheme
This allows us to re-instantiate existentials.scala.
1 parent 48a2ab3 commit fe470c4

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

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

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,22 @@ object TypeApplications {
8181
* `>: L <: H` is substituted for a type lambda parameter `X` only under certain conditions.
8282
*
8383
* 1. If Mode.AllowLambdaWildcardApply is set:
84-
* The wildcard argument is substituted only if `X` appears in a toplevel refinement of the form
84+
* The wildcard argument is substituted only if `X` appears in a toplevel application of the form
8585
*
86-
* { type A = X }
86+
* C[..., X, ...]
8787
*
8888
* and there are no other occurrences of `X` in the reduced type. In that case
8989
* the refinement above is replaced by
9090
*
91-
* { type A >: L <: U }
91+
* C[..., _ >: L <: H, ...]
9292
*
9393
* The `allReplaced` field indicates whether all occurrences of type lambda parameters
9494
* in the reduced type have been replaced with arguments.
9595
*
9696
* 2. If Mode.AllowLambdaWildcardApply is not set:
97-
* All refinements of the form
97+
* All `X` arguments are replaced by:
9898
*
99-
* { type A = X }
100-
*
101-
* are replaced by:
102-
*
103-
* { type A >: L <: U }
99+
* _ >: L <: H
104100
*
105101
* Any other occurrence of `X` in `tycon` is replaced by `U`, if the
106102
* occurrence of `X` in `tycon` is covariant, or nonvariant, or by `L`,
@@ -121,6 +117,12 @@ object TypeApplications {
121117
p.binder == tycon && args(p.paramNum).isInstanceOf[TypeBounds]
122118
def canReduceWildcard(p: TypeParamRef) =
123119
!ctx.mode.is(Mode.AllowLambdaWildcardApply) || available.contains(p.paramNum)
120+
def atNestedLevel(op: => Type): Type = {
121+
val saved = available
122+
available = Set()
123+
try op
124+
finally available = saved
125+
}
124126

125127
// If this is a reference to a reducable type parameter corresponding to a
126128
// wildcard argument, return the wildcard argument, otherwise apply recursively.
@@ -129,13 +131,10 @@ object TypeApplications {
129131
available -= p.paramNum
130132
args(p.paramNum)
131133
case _ =>
132-
apply(arg)
134+
atNestedLevel(apply(arg))
133135
}
134136

135137
def apply(t: Type) = t match {
136-
case t @ TypeAlias(p: TypeParamRef) if hasWildcardArg(p) && canReduceWildcard(p) =>
137-
available -= p.paramNum // @!!! needed in the future?
138-
args(p.paramNum)
139138
case t @ AppliedType(tycon, args1) if tycon.typeSymbol.isClass =>
140139
t.derivedAppliedType(apply(tycon), args1.mapConserve(applyArg))
141140
case p: TypeParamRef if p.binder == tycon =>
@@ -148,10 +147,7 @@ object TypeApplications {
148147
arg
149148
}
150149
case _: TypeBounds | _: AppliedType =>
151-
val saved = available
152-
available = Set()
153-
try mapOver(t)
154-
finally available = saved
150+
atNestedLevel(mapOver(t))
155151
case _ =>
156152
mapOver(t)
157153
}
File renamed without changes.

0 commit comments

Comments
 (0)