From 379af580e2c8cf0ce5309fc0b31702f79e415abe Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 4 Nov 2010 00:07:36 +0000 Subject: Determined that half a dozen ways of checking f... Determined that half a dozen ways of checking for varargs and by-name-ness in param lists exceeded the legal limit. Also assessed that names which are only used as type names would be a lot easier to deal with if we created them as type names up front. Performed the changes implied by the preceding along with a partial cleanup on TreeInfo which one can see hasn't had a good look in a long time. (And still hasn't.) No review. --- .../scala/tools/nsc/ast/parser/Parsers.scala | 26 ++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'src/compiler/scala/tools/nsc/ast/parser/Parsers.scala') diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index b3aaf02195..5a63b49aac 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -443,14 +443,12 @@ self => def errorTermTree = Literal(Constant(null)).setPos(o2p(in.offset)) def errorPatternTree = Ident(nme.WILDCARD).setPos(o2p(in.offset)) - /** Check that type parameter is not by name T* */ - def checkNotByName(t: Tree) = t match { - case AppliedTypeTree(Select(_, n), _) => - if (n == nme.BYNAME_PARAM_CLASS_NAME.toTypeName) - syntaxError(t.pos, "no by-name parameter type allowed here", false) - else if (n == nme.REPEATED_PARAM_CLASS_NAME.toTypeName) - syntaxError(t.pos, "no * parameter type allowed here", false) - case _ => + /** Check that type parameter is not by name or repeated */ + def checkNotByNameOrVarargs(tpt: Tree) = { + if (treeInfo isByNameParamType tpt) + syntaxError(tpt.pos, "no by-name parameter type allowed here", false) + else if (treeInfo isRepeatedParamType tpt) + syntaxError(tpt.pos, "no * parameter type allowed here", false) } /** Check that tree is a legal clause of a forSome */ @@ -867,7 +865,7 @@ self => makeFunctionTypeTree(ts, typ(isPattern)) } else { - ts foreach checkNotByName + ts foreach checkNotByNameOrVarargs val tuple = atPos(start) { makeTupleType(ts, true) } infixTypeRest( compoundTypeRest( @@ -1036,12 +1034,12 @@ self => // copy-paste (with change) from def paramType if (in.token == ARROW) { in.nextToken() - val tycon = atPos(start) { rootScalaDot(nme.BYNAME_PARAM_CLASS_NAME.toTypeName) } + val tycon = atPos(start) { rootScalaDot(nme.BYNAME_PARAM_CLASS_NAME) } atPos(start) { AppliedTypeTree(tycon, List(typ())) } } else { val t = typ() if (isIdent && in.name == STAR) { - val tycon = atPos(in.skipToken()) { rootScalaDot(nme.REPEATED_PARAM_CLASS_NAME.toTypeName) } + val tycon = atPos(in.skipToken()) { rootScalaDot(nme.REPEATED_PARAM_CLASS_NAME) } atPos(start) { AppliedTypeTree(tycon, List(t)) } } else t } @@ -1195,7 +1193,7 @@ self => if (isIdent && in.name == nme.STAR) { in.nextToken() t = atPos(t.pos.startOrPoint, colonPos) { - Typed(t, atPos(uscorePos) { Ident(nme.WILDCARD_STAR.toTypeName) }) + Typed(t, atPos(uscorePos) { Ident(nme.WILDCARD_STAR) }) } } else { syntaxErrorOrIncomplete("`*' expected", true) @@ -1917,7 +1915,7 @@ self => if (in.token == ARROW) { atPos(in.skipToken()) { AppliedTypeTree( - rootScalaDot(nme.BYNAME_PARAM_CLASS_NAME.toTypeName), List(typ())) + rootScalaDot(nme.BYNAME_PARAM_CLASS_NAME), List(typ())) } } else { val t = typ() @@ -1925,7 +1923,7 @@ self => in.nextToken() atPos(t.pos.startOrPoint, t.pos.point) { AppliedTypeTree( - rootScalaDot(nme.REPEATED_PARAM_CLASS_NAME.toTypeName), List(t)) + rootScalaDot(nme.REPEATED_PARAM_CLASS_NAME), List(t)) } } else t } -- cgit v1.2.3