diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 6 | ||||
-rw-r--r-- | test/files/run/names-defaults.scala | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index c2d69637b1..7c1e072849 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1219,6 +1219,12 @@ trait Typers { self: Analyzer => def typedModuleDef(mdef: ModuleDef): Tree = { //Console.println("sourcefile of " + mdef.symbol + "=" + mdef.symbol.sourceFile) // attributes(mdef) + // initialize all constructors of the linked class: the type completer (Namer.methodSig) + // might add default getters to this object. example: "object T; class T(x: Int = 1)" + val linkedClass = mdef.symbol.linkedClassOfModule + if (linkedClass != NoSymbol) + for (c <- linkedClass.info.decl(nme.CONSTRUCTOR).alternatives) + c.initialize val clazz = mdef.symbol.moduleClass val typedMods = removeAnnotations(mdef.mods) assert(clazz != NoSymbol) diff --git a/test/files/run/names-defaults.scala b/test/files/run/names-defaults.scala index 91f72e3e3c..1d737bb0c7 100644 --- a/test/files/run/names-defaults.scala +++ b/test/files/run/names-defaults.scala @@ -229,6 +229,13 @@ object Test extends Application { def transform(s: String, f: String => String = identity _) = f(s) println(transform("my text")) + + // a bug reported on a mailing list: see comment in Typer.typedModuleDef + object TT + class TT(x: Int = 1) + val v = new TT() + + // result type of the default getter is inferred (parameter type mentions type parameter T) def test10[T](x: List[T] = List(1,2)) = x println(test10()) |