diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-07-24 07:26:27 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-07-24 07:26:27 +0000 |
commit | f4301266d3eb395f0aaab3211eaaeaff898f9961 (patch) | |
tree | 34a02895c8ca98451e9272d13090b56b4e7ae870 | |
parent | 50b5242ee355b32266b7c061b696ecad8f84332f (diff) | |
download | scala-f4301266d3eb395f0aaab3211eaaeaff898f9961.tar.gz scala-f4301266d3eb395f0aaab3211eaaeaff898f9961.tar.bz2 scala-f4301266d3eb395f0aaab3211eaaeaff898f9961.zip |
fixed a bug with defaults reported on mailing list
-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()) |