From 693ecffbaf5be036e05300a1ee3a8444c0ac0fe3 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 27 Sep 2013 00:32:40 -0700 Subject: Fix up DEFAULTPARAM semantics. I foolishly believed the deprecation message on "hasDefaultFlag" which suggested I use "hasDefault" instead. After lots of head scratching, I hardened the semantics so it's like this: - A method parameter with a default value is PARAM | DEFAULTPARAM - A default getter for such a parameter is METHOD | DEFAULTPARAM - And "hasDefault" is has(DEFAULTPARAM) && has(PARAM | METHOD) Why all the bonus logic, why not just hasFlag(DEFAULTPARAM)? For some reason we have a handful of overloaded flags spanning uses which someone apparently thinks can never intersect but I have not been so lucky overall. So since DEFAULTPARAM is overloaded with TRAIT, unless we think it's fine that default getters and method parameters with defaults will pose as traits all the time, there has to be an anchor bit alongside it. --- src/compiler/scala/tools/nsc/typechecker/Namers.scala | 4 +--- src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 347426d42a..4cfac91a94 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -1272,9 +1272,7 @@ trait Namers extends MethodSynthesis { val defRhs = copyUntyped(vparam.rhs) val defaultTree = atPos(vparam.pos.focus) { - DefDef( - Modifiers(meth.flags & DefaultGetterFlags) | (SYNTHETIC | DEFAULTPARAM | oflag).toLong, - name, deftParams, defvParamss, defTpt, defRhs) + DefDef(Modifiers(paramFlagsToDefaultGetter(meth.flags)) | oflag, name, deftParams, defvParamss, defTpt, defRhs) } if (!isConstr) methOwner.resetFlag(INTERFACE) // there's a concrete member now diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 61759a9f00..0ac81af56f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -127,14 +127,14 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans // those with the DEFAULTPARAM flag, and infer the methods. Looking for the methods // directly requires inspecting the parameter list of every one. That modification // shaved 95% off the time spent in this method. - val defaultGetters = defaultClass.info.findMembers(0L, DEFAULTPARAM) + val defaultGetters = defaultClass.info.findMembers(excludedFlags = PARAM, requiredFlags = DEFAULTPARAM) val defaultMethodNames = defaultGetters map (sym => nme.defaultGetterToMethod(sym.name)) defaultMethodNames.toList.distinct foreach { name => - val methods = clazz.info.findMember(name, 0L, METHOD, stableOnly = false).alternatives + val methods = clazz.info.findMember(name, 0L, requiredFlags = METHOD, stableOnly = false).alternatives def hasDefaultParam(tpe: Type): Boolean = tpe match { case MethodType(params, restpe) => (params exists (_.hasDefault)) || hasDefaultParam(restpe) - case _ => false + case _ => false } val haveDefaults = methods filter (sym => hasDefaultParam(sym.info) && !nme.isProtectedAccessorName(sym.name)) -- cgit v1.2.3