diff options
author | mihaylov <mihaylov@epfl.ch> | 2006-06-13 14:47:26 +0000 |
---|---|---|
committer | mihaylov <mihaylov@epfl.ch> | 2006-06-13 14:47:26 +0000 |
commit | 150014366e457e0a30f185b4debca2303f0f58d3 (patch) | |
tree | 9f6a0e7276121a69bbedbb3ca32cb5443a4734fb | |
parent | e5556bbbe0821456afbe9c0a55f4de53ed05d4ad (diff) | |
download | scala-150014366e457e0a30f185b4debca2303f0f58d3.tar.gz scala-150014366e457e0a30f185b4debca2303f0f58d3.tar.bz2 scala-150014366e457e0a30f185b4debca2303f0f58d3.zip |
Improved error handling for name-value pairs in...
Improved error handling for name-value pairs in attributes
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 0fad675192..2c1fe236f3 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1354,39 +1354,39 @@ trait Typers requires Analyzer { typer1.typedLabelDef(ldef) case Attributed(Attribute(constr, elements), defn) => - val constr1 = typed(constr, mode | CONSTmode, AttributeClass.tpe) - val attrInfo = constr1 match { + var attrError: Boolean = false; + def getConstant(tree: Tree): Constant = tree match { + case Literal(value) => + value + case arg => + error(arg.pos, "attribute argument needs to be a constant; found: "+arg) + attrError = true; + null + } + typed(constr, mode | CONSTmode, AttributeClass.tpe) match { case Apply(Select(New(tpt), nme.CONSTRUCTOR), args) => - val constrArgs = args map { - case Literal(value) => - value - case arg => - error(arg.pos, "attribute argument needs to be a constant; found: "+arg) - null - } + val constrArgs = args map getConstant + val attrScope = tpt.tpe.decls; val nvPairs = elements map { - case Assign(Ident(name), rhs) => { - val sym = tpt.tpe.decls.lookupEntry(name).sym; + case Assign(ntree @ Ident(name), rhs) => { + val sym = attrScope.lookup(name); if (sym == NoSymbol) { + error(ntree.pos, "unknown attribute element name: " + name) + attrError = true; null } else { - val rhs1 = typed(rhs, mode | CONSTmode, sym.tpe.resultType) - val value = rhs1 match { - case Literal(v) => v - case arg => - error(arg.pos, "attribute argument needs to be a constant; found: "+arg) - null - } - Pair(sym, value) + Pair(sym, getConstant(typed(rhs, mode | CONSTmode, + sym.tpe.resultType))) } } } - Triple(tpt.tpe, constrArgs, nvPairs) - } - if (attrInfo != null) { - val attributed = - if (defn.symbol.isModule) defn.symbol.moduleClass else defn.symbol; - attributed.attributes = attributed.attributes ::: List(attrInfo) + if (!attrError) { + val attrInfo = Triple(tpt.tpe, constrArgs, nvPairs) + val attributed = + if (defn.symbol.isModule) defn.symbol.moduleClass + else defn.symbol; + attributed.attributes = attributed.attributes ::: List(attrInfo) + } } typed(defn, mode, pt) |