diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-09-24 15:38:59 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-09-24 15:38:59 +0000 |
commit | fb38e47af1dec087a11585c6878c70ccdc930312 (patch) | |
tree | ec523de0da8e383baae9d342198a1d3bfa6df366 /src/compiler | |
parent | e1b326195e47fe28cbbd9585e2e15dddf0bb1361 (diff) | |
download | scala-fb38e47af1dec087a11585c6878c70ccdc930312.tar.gz scala-fb38e47af1dec087a11585c6878c70ccdc930312.tar.bz2 scala-fb38e47af1dec087a11585c6878c70ccdc930312.zip |
fix for #2382
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 9efc9827c2..1b2fde4f4a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -906,15 +906,20 @@ trait Namers { self: Analyzer => addDefaultGetters(meth, vparamss, tparams, overriddenSymbol) - thisMethodType( - if (tpt.isEmpty) { + thisMethodType({ + val rt = if (tpt.isEmpty) { // replace deSkolemized symbols with skolemized ones (for resultPt computed by looking at overridden symbol, right?) val pt = resultPt.substSym(tparamSyms, tparams map (_.symbol)) // compute result type from rhs tpt.tpe = widenIfNotFinal(meth, typer.computeType(rhs, pt), pt) tpt setPos meth.pos.focus tpt.tpe - } else typer.typedType(tpt).tpe) + } else typer.typedType(tpt).tpe + // #2382: return type of default getters are always @uncheckedVariance + if (meth.hasFlag(DEFAULTPARAM)) + rt.withAnnotation(AnnotationInfo(definitions.uncheckedVarianceClass.tpe, List(), List())) + else rt + }) } /** @@ -989,9 +994,9 @@ trait Namers { self: Analyzer => // If the parameter type mentions any type parameter of the method, let the compiler infer the // return type of the default getter => allow "def foo[T](x: T = 1)" to compile. - // This is better than always inferring the result type, for example in + // This is better than always using Wildcard for inferring the result type, for example in // def f(i: Int, m: Int => Int = identity _) = m(i) - // if we infer the default's type, we get "Nothing => Nothing", and the default is not usable. + // if we use Wildcard as expected, we get "Nothing => Nothing", and the default is not usable. val names = deftParams map { case TypeDef(_, name, _, _) => name } object subst extends Transformer { override def transform(tree: Tree): Tree = tree match { @@ -1002,8 +1007,8 @@ trait Namers { self: Analyzer => } def apply(tree: Tree) = { val r = transform(tree) - if (r.find(_.isEmpty).isEmpty) r - else TypeTree() + if (r.exists(_.isEmpty)) TypeTree() + else r } } |