Skip to content

Commit 182e590

Browse files
committed
Use atVariance for new cases in TypeMaps and TypeAccumulators
1 parent e144a4e commit 182e590

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3926,13 +3926,9 @@ object Types {
39263926
| _: BoundType
39273927
| NoPrefix => tp
39283928

3929-
case tp: AppliedType => // @!!! use atVariance
3930-
def mapArg(arg: Type, tparam: ParamInfo): Type = {
3931-
val saved = variance
3932-
variance *= tparam.paramVariance
3933-
try this(arg)
3934-
finally variance = saved
3935-
}
3929+
case tp: AppliedType =>
3930+
def mapArg(arg: Type, tparam: ParamInfo): Type =
3931+
atVariance(variance * tparam.paramVariance)(this(arg))
39363932
derivedAppliedType(tp, this(tp.tycon),
39373933
tp.args.zipWithConserve(tp.typeParams)(mapArg))
39383934

@@ -3974,11 +3970,7 @@ object Types {
39743970
mapOverLambda
39753971

39763972
case tp @ TypeArgRef(prefix, _, _) =>
3977-
val saved = variance
3978-
variance = 0
3979-
val prefix1 = this(prefix)
3980-
variance = saved
3981-
derivedTypeArgRef(tp, prefix1)
3973+
derivedTypeArgRef(tp, atVariance(0)(this(prefix)))
39823974

39833975
case tp @ SuperType(thistp, supertp) =>
39843976
derivedSuperType(tp, this(thistp), this(supertp))
@@ -4359,13 +4351,9 @@ object Types {
43594351
assert(tparams.isEmpty)
43604352
x
43614353
}
4362-
else { // @@!!! use atVariance
4354+
else {
43634355
val tparam = tparams.head
4364-
val saved = variance
4365-
variance *= tparam.paramVariance
4366-
val acc =
4367-
try this(x, args.head)
4368-
finally variance = saved
4356+
val acc = atVariance(variance * tparam.paramVariance)(this(x, args.head))
43694357
foldArgs(acc, tparams.tail, args.tail)
43704358
}
43714359
foldArgs(this(x, tycon), tp.typeParams, args)

0 commit comments

Comments
 (0)