Skip to content

Commit fb38e47

Browse files
committedSep 24, 2009
fix for #2382
1 parent e1b3261 commit fb38e47

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed
 

‎src/compiler/scala/tools/nsc/typechecker/Namers.scala

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -906,15 +906,20 @@ trait Namers { self: Analyzer =>
906906

907907
addDefaultGetters(meth, vparamss, tparams, overriddenSymbol)
908908

909-
thisMethodType(
910-
if (tpt.isEmpty) {
909+
thisMethodType({
910+
val rt = if (tpt.isEmpty) {
911911
// replace deSkolemized symbols with skolemized ones (for resultPt computed by looking at overridden symbol, right?)
912912
val pt = resultPt.substSym(tparamSyms, tparams map (_.symbol))
913913
// compute result type from rhs
914914
tpt.tpe = widenIfNotFinal(meth, typer.computeType(rhs, pt), pt)
915915
tpt setPos meth.pos.focus
916916
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+
})
918923
}
919924

920925
/**
@@ -989,9 +994,9 @@ trait Namers { self: Analyzer =>
989994

990995
// If the parameter type mentions any type parameter of the method, let the compiler infer the
991996
// 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
993998
// 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.
9951000
val names = deftParams map { case TypeDef(_, name, _, _) => name }
9961001
object subst extends Transformer {
9971002
override def transform(tree: Tree): Tree = tree match {
@@ -1002,8 +1007,8 @@ trait Namers { self: Analyzer =>
10021007
}
10031008
def apply(tree: Tree) = {
10041009
val r = transform(tree)
1005-
if (r.find(_.isEmpty).isEmpty) r
1006-
else TypeTree()
1010+
if (r.exists(_.isEmpty)) TypeTree()
1011+
else r
10071012
}
10081013
}
10091014

‎test/files/run/names-defaults.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ object Test extends Application {
257257
spawn(b = { val ttt = 1; ttt }, a = 0)
258258
}
259259

260+
// # 2382
261+
class A2382[+T](x: T => Int) { def foo(a: T => Int = x) = 0 }
262+
260263

261264
// DEFINITIONS
262265
def test1(a: Int, b: String) = println(a +": "+ b)

0 commit comments

Comments
 (0)
Please sign in to comment.