@@ -83,24 +83,21 @@ class VarianceChecker()(implicit ctx: Context) {
83
83
private object Validator extends TypeAccumulator [Option [VarianceError ]] {
84
84
private var base : Symbol = _
85
85
86
- /** Is no variance checking needed within definition of `base`? */
87
- def ignoreVarianceIn (base : Symbol ): Boolean = (
88
- base.isTerm
89
- || base.is(Package )
90
- || base.isAllOf(PrivateLocal )
91
- )
92
-
93
86
/** The variance of a symbol occurrence of `tvar` seen at the level of the definition of `base`.
94
87
* The search proceeds from `base` to the owner of `tvar`.
95
88
* Initially the state is covariant, but it might change along the search.
96
89
*/
97
90
def relativeVariance (tvar : Symbol , base : Symbol , v : Variance = Covariant ): Variance = /* trace(i"relative variance of $tvar wrt $base, so far: $v")*/
98
- if (base == tvar.owner) v
99
- else if (base.is(Param ) && base.owner.isTerm)
91
+ if base == tvar.owner then
92
+ v
93
+ else if base.is(Param ) && base.owner.isTerm && ! base.owner.isAllOf(PrivateLocal ) then
100
94
relativeVariance(tvar, paramOuter(base.owner), flip(v))
101
- else if (ignoreVarianceIn(base.owner)) Bivariant
102
- else if (base.isAliasType) relativeVariance(tvar, base.owner, Invariant )
103
- else relativeVariance(tvar, base.owner, v)
95
+ else if base.owner.isTerm || base.owner.is(Package ) || base.isAllOf(PrivateLocal ) then
96
+ Bivariant
97
+ else if base.isAliasType then
98
+ relativeVariance(tvar, base.owner, Invariant )
99
+ else
100
+ relativeVariance(tvar, base.owner, v)
104
101
105
102
/** The next level to take into account when determining the
106
103
* relative variance with a method parameter as base. The method
@@ -189,11 +186,10 @@ class VarianceChecker()(implicit ctx: Context) {
189
186
override def traverse (tree : Tree )(implicit ctx : Context ) = {
190
187
def sym = tree.symbol
191
188
// No variance check for private/protected[this] methods/values.
192
- def skip =
193
- ! sym.exists ||
194
- sym.isAllOf(PrivateLocal ) ||
195
- sym.name.is(InlineAccessorName ) || // TODO: should we exclude all synthetic members?
196
- sym.is(TypeParam ) && sym.owner.isClass // already taken care of in primary constructor of class
189
+ def skip = ! sym.exists
190
+ || sym.name.is(InlineAccessorName ) // TODO: should we exclude all synthetic members?
191
+ || sym.isAllOf(LocalParamAccessor ) // local class parameters are construction only
192
+ || sym.is(TypeParam ) && sym.owner.isClass // already taken care of in primary constructor of class
197
193
try tree match {
198
194
case defn : MemberDef if skip =>
199
195
ctx.debuglog(s " Skipping variance check of ${sym.showDcl}" )
0 commit comments