diff options
author | Martin Odersky <odersky@gmail.com> | 2007-03-30 10:29:26 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2007-03-30 10:29:26 +0000 |
commit | b739c4a2eccfe4c8846e5e523ede121f81886a65 (patch) | |
tree | 2651646a743b9ad52cc54783e49d9291057a0949 /src/compiler | |
parent | c1d1fec365efbb7ee4798594784458b3f5be4dcf (diff) | |
download | scala-b739c4a2eccfe4c8846e5e523ede121f81886a65.tar.gz scala-b739c4a2eccfe4c8846e5e523ede121f81886a65.tar.bz2 scala-b739c4a2eccfe4c8846e5e523ede121f81886a65.zip |
assumes () parameterless if overridden method h...
assumes () parameterless if overridden method has one. This should fix
problems with toString.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 8ab4b50aa2..f843059872 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -459,9 +459,12 @@ trait Namers requires Analyzer { val meth = context.owner val tparamSyms = typer.reenterTypeParams(tparams) - val vparamSymss = enterValueParams(meth, vparamss) + var vparamSymss = enterValueParams(meth, vparamss) if (tpt.isEmpty && meth.name == nme.CONSTRUCTOR) tpt.tpe = context.enclClass.owner.tpe + if (onlyPresentation) + methodArgumentNames(meth) = vparamss.map(.map(.symbol)); + def makeMethodType(vparams: List[Symbol], restpe: Type) = { val formals = vparams map (.tpe) if (!vparams.isEmpty && vparams.head.hasFlag(IMPLICIT)) ImplicitMethodType(formals, restpe) @@ -475,19 +478,17 @@ trait Namers requires Analyzer { else (vparamSymss :\ restype)(makeMethodType)) var resultPt = if (tpt.isEmpty) WildcardType else typer.typedType(tpt).tpe + val site = meth.owner.thisType - if (onlyPresentation) - methodArgumentNames(meth) = vparamss.map(.map(.symbol)); + def overriddenSymbol = intersectionType(meth.owner.info.parents).member(meth.name).filter(sym => + sym != NoSymbol && (site.memberType(sym) matches thisMethodType(resultPt))) + + // fill in result type and parameter types from overridden symbol if there is a unique one. if (meth.owner.isClass && (tpt.isEmpty || vparamss.exists(.exists(.tpt.isEmpty)))) { // try to complete from matching definition in base type for (val vparams <- vparamss; val vparam <- vparams) if (vparam.tpt.isEmpty) vparam.symbol setInfo WildcardType - val schema = thisMethodType(resultPt) - val site = meth.owner.thisType - - - val overridden = intersectionType(meth.owner.info.parents).member(meth.name).filter(sym => - sym != NoSymbol && (site.memberType(sym) matches schema)) + val overridden = overriddenSymbol if (overridden != NoSymbol && !(overridden hasFlag OVERLOADED)) { resultPt = site.memberType(overridden) match { case PolyType(tparams, rt) => rt.substSym(tparams, tparamSyms) @@ -517,7 +518,11 @@ trait Namers requires Analyzer { } } } - + // Add a () parameter section if this overrides dome method with () parameters. + if (meth.owner.isClass && vparamss.isEmpty && overriddenSymbol.alternatives.exists( + .info.isInstanceOf[MethodType])) { + vparamSymss = List(List()) + } for (val vparams <- vparamss; val vparam <- vparams; vparam.tpt.isEmpty) { context.error(vparam.pos, "missing parameter type") vparam.tpt.tpe = ErrorType |