File tree 2 files changed +22
-3
lines changed
compiler/src/dotty/tools/dotc/typer
2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -130,8 +130,6 @@ class VarianceChecker(using Context) {
130
130
case TypeAlias (alias) => this (status, alias)
131
131
case _ => foldOver(status, tp)
132
132
}
133
- case tp : MethodOrPoly =>
134
- this (status, tp.resultType) // params will be checked in their TypeDef or ValDef nodes.
135
133
case AnnotatedType (_, annot) if annot.symbol == defn.UncheckedVarianceAnnot =>
136
134
status
137
135
case tp : ClassInfo =>
@@ -144,10 +142,16 @@ class VarianceChecker(using Context) {
144
142
}
145
143
}
146
144
145
+ def checkInfo (info : Type ): Option [VarianceError ] = info match
146
+ case info : MethodOrPoly =>
147
+ checkInfo(info.resultType) // params will be checked in their TypeDef or ValDef nodes.
148
+ case _ =>
149
+ apply(None , info)
150
+
147
151
def validateDefinition (base : Symbol ): Option [VarianceError ] = {
148
152
val saved = this .base
149
153
this .base = base
150
- try apply( None , base.info)
154
+ try checkInfo( base.info)
151
155
finally this .base = saved
152
156
}
153
157
}
Original file line number Diff line number Diff line change
1
+ import reflect .Selectable .reflectiveSelectable
2
+
3
+ class A [+ Cov ](f : Cov => Unit ) {
4
+ def foo : { def apply (c : Cov ): Unit } = // error
5
+ f
6
+ }
7
+
8
+ val aForString = new A [String ](_.length)
9
+ // => val aForString: A[String]
10
+
11
+ val aForStringIsAForAny : A [Any ] = aForString
12
+ // => val aForStringIsAForAny: A[Any]
13
+
14
+ val _ = aForStringIsAForAny.foo(123 )
15
+ // => java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String (java.lang.Integer and java.lang.String are in module java.base of loader 'bootstrap')
You can’t perform that action at this time.
0 commit comments