@@ -906,15 +906,20 @@ trait Namers { self: Analyzer =>
906
906
907
907
addDefaultGetters(meth, vparamss, tparams, overriddenSymbol)
908
908
909
- thisMethodType(
910
- if (tpt.isEmpty) {
909
+ thisMethodType({
910
+ val rt = if (tpt.isEmpty) {
911
911
// replace deSkolemized symbols with skolemized ones (for resultPt computed by looking at overridden symbol, right?)
912
912
val pt = resultPt.substSym(tparamSyms, tparams map (_.symbol))
913
913
// compute result type from rhs
914
914
tpt.tpe = widenIfNotFinal(meth, typer.computeType(rhs, pt), pt)
915
915
tpt setPos meth.pos.focus
916
916
tpt.tpe
917
- } else typer.typedType(tpt).tpe)
917
+ } else typer.typedType(tpt).tpe
918
+ // #2382: return type of default getters are always @uncheckedVariance
919
+ if (meth.hasFlag(DEFAULTPARAM ))
920
+ rt.withAnnotation(AnnotationInfo (definitions.uncheckedVarianceClass.tpe, List (), List ()))
921
+ else rt
922
+ })
918
923
}
919
924
920
925
/**
@@ -989,9 +994,9 @@ trait Namers { self: Analyzer =>
989
994
990
995
// If the parameter type mentions any type parameter of the method, let the compiler infer the
991
996
// return type of the default getter => allow "def foo[T](x: T = 1)" to compile.
992
- // This is better than always inferring the result type, for example in
997
+ // This is better than always using Wildcard for inferring the result type, for example in
993
998
// def f(i: Int, m: Int => Int = identity _) = m(i)
994
- // if we infer the default's type , we get "Nothing => Nothing", and the default is not usable.
999
+ // if we use Wildcard as expected , we get "Nothing => Nothing", and the default is not usable.
995
1000
val names = deftParams map { case TypeDef (_, name, _, _) => name }
996
1001
object subst extends Transformer {
997
1002
override def transform (tree : Tree ): Tree = tree match {
@@ -1002,8 +1007,8 @@ trait Namers { self: Analyzer =>
1002
1007
}
1003
1008
def apply (tree : Tree ) = {
1004
1009
val r = transform(tree)
1005
- if (r.find (_.isEmpty).isEmpty) r
1006
- else TypeTree ()
1010
+ if (r.exists (_.isEmpty)) TypeTree ()
1011
+ else r
1007
1012
}
1008
1013
}
1009
1014
0 commit comments