Skip to content

Commit 63a49b5

Browse files
committed
Treat variances in type accumulators and type maps the same
Bonus point: No need to override applyPrefix in variances accumulator. This means we have reduced three different ways to compute the current variance to one.
1 parent 1667cc3 commit 63a49b5

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -3924,9 +3924,9 @@ object Types {
39243924

39253925
protected var variance = 1
39263926

3927-
protected def applyToPrefix(x: T, tp: NamedType) = {
3927+
protected final def applyToPrefix(x: T, tp: NamedType) = {
39283928
val saved = variance
3929-
variance = 0
3929+
variance = variance max 0 // see remark on NamedType case in TypeMap
39303930
val result = this(x, tp.prefix)
39313931
variance = saved
39323932
result

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

-2
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,6 @@ object Inferencing {
319319
case _ =>
320320
foldOver(vmap, t)
321321
}
322-
override def applyToPrefix(vmap: VarianceMap, t: NamedType) =
323-
apply(vmap, t.prefix)
324322
}
325323

326324
/** Include in `vmap` type variables occurring in the constraints of type variables

0 commit comments

Comments
 (0)