diff options
author | Paul Phillips <paulp@improving.org> | 2010-11-04 00:07:36 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-11-04 00:07:36 +0000 |
commit | 379af580e2c8cf0ce5309fc0b31702f79e415abe (patch) | |
tree | cf741eb0d27624d6130bb5bc7f403ec7fb05af1d /src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | |
parent | de012b3a6d04f1e7a9fd6fecd403e0492f6ad7c1 (diff) | |
download | scala-379af580e2c8cf0ce5309fc0b31702f79e415abe.tar.gz scala-379af580e2c8cf0ce5309fc0b31702f79e415abe.tar.bz2 scala-379af580e2c8cf0ce5309fc0b31702f79e415abe.zip |
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.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/Parsers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 26 |
1 files changed, 12 insertions, 14 deletions
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 } |