From 0d9486124afb366cf35a52349ce3adc416a01757 Mon Sep 17 00:00:00 2001 From: paltherr Date: Fri, 21 Feb 2003 15:50:19 +0000 Subject: - Improved the error messages --- sources/scalac/ast/Tree.java | 67 +++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/sources/scalac/ast/Tree.java b/sources/scalac/ast/Tree.java index 6ee74544e1..7f29e956f9 100644 --- a/sources/scalac/ast/Tree.java +++ b/sources/scalac/ast/Tree.java @@ -9,7 +9,7 @@ package scalac.ast; import scalac.ast.printer.*; -import scalac.ApplicationError; +import scalac.util.Debug; import scalac.util.Name; import scalac.util.Position; import scalac.symtab.Type; @@ -49,7 +49,7 @@ public class Tree { public case PackageDef(Tree packaged, Template impl) { if (!packaged.isTerm()) - throw new ApplicationError("PackageDef expects term as rhs."); + throw unexpected("PackageDef expects term as rhs", packaged); } /** module declaration @@ -69,9 +69,9 @@ public class Tree { Tree rhs) { assert !name.isTypeName(); if (!tpe.isType()) - throw new ApplicationError("ValDef expects type as tpe; found: " + tpe); + throw unexpected("ValDef expects type as tpe", tpe); if (!rhs.isTerm()) - throw new ApplicationError("ValDef expects term as rhs."); + throw unexpected("ValDef expects term as rhs", rhs); } /** val declaration @@ -80,7 +80,7 @@ public class Tree { Tree pat, Tree rhs) { if (!rhs.isTerm()) - throw new ApplicationError("PatDef expects term as rhs."); + throw unexpected("PatDef expects term as rhs", rhs); } /** def declaration @@ -93,9 +93,9 @@ public class Tree { Tree rhs) { assert !name.isTypeName(); if (!tpe.isType()) - throw new ApplicationError("DefDef expects type as tpe."); + throw unexpected("DefDef expects type as tpe", tpe); if (!rhs.isTerm()) - throw new ApplicationError("DefDef expects term as rhs. Found: " + rhs.getClass()); + throw unexpected("DefDef expects term as rhs", rhs); } /** type declaration @@ -106,14 +106,14 @@ public class Tree { Tree rhs) { assert name.isTypeName(); if (!rhs.isType()) - throw new ApplicationError("TypeDef expects type as rhs; found: " + rhs); + throw unexpected("TypeDef expects type as rhs", rhs); } /** import declaration */ public case Import(Tree expr, Name[] selectors) { if (!expr.isTerm()) - throw new ApplicationError("Import expects term."); + throw unexpected("Import expects term", expr); } /** case declaration @@ -122,9 +122,9 @@ public class Tree { Tree guard, Tree body) { if (!guard.isTerm()) - throw new ApplicationError("CaseDef expects term as guard."); + throw unexpected("CaseDef expects term as guard", guard); if (!body.isTerm()) - throw new ApplicationError("CaseDef expects term as body."); + throw unexpected("CaseDef expects term as body", body); } /** instantiation templates @@ -134,7 +134,7 @@ public class Tree { if (parents != null) { for (int i = 0; i < parents.length; i++) { if (!parents[i].isTerm()) - throw new ApplicationError("Template requires terms as baseClasses."); + throw unexpected("Template requires terms as baseClasses", parents[i]); } } } @@ -145,7 +145,7 @@ public class Tree { public case LabelDef(Tree[] params,Tree rhs) { for (int i = 0;i < params.length; i++) { if (!(params[i] instanceof Ident)) - throw new ApplicationError("LabelDef requires Idents"); + throw unexpected("LabelDef requires Idents", params[i]); } } @@ -159,7 +159,7 @@ public class Tree { if (trees != null) { for (int i = 0; i < trees.length; i++) { if (!trees[i].isTerm()) - throw new ApplicationError("Tuple requires terms"); + throw unexpected("Tuple requires terms", trees[i]); } } } @@ -173,7 +173,7 @@ public class Tree { public case Function(ValDef[] vparams, Tree body) { if (!body.isTerm()) - throw new ApplicationError("Function body has to be a term."); + throw unexpected("Function body has to be a term", body); } /** assignment @@ -181,9 +181,9 @@ public class Tree { public case Assign(Tree lhs, Tree rhs) { if (!lhs.isTerm()) - throw new ApplicationError("lhs of Assign has to be a term."); + throw unexpected("lhs of Assign has to be a term", lhs); if (!rhs.isTerm()) - throw new ApplicationError("rhs of Assign has to be a term."); + throw unexpected("rhs of Assign has to be a term", rhs); } /** conditional expression @@ -205,9 +205,9 @@ public class Tree { public case Typed(Tree expr, Tree tpe) { if (!expr.isTerm()) - throw new ApplicationError("Typed expects term as first argument."); + throw unexpected("Typed expects term as first argument", expr); if (!tpe.isType()) - throw new ApplicationError("Typed expects type as second argument."); + throw unexpected("Typed expects type as second argument", tpe); } /** type application @@ -216,11 +216,11 @@ public class Tree { Tree[] args) { if (!fun.isTerm()) { new TextTreePrinter().print(fun).println().end();//debug - throw new ApplicationError("TypeApply expects term as function."); + throw unexpected("TypeApply expects term as function", fun); } for (int i = 0; i < args.length; i++) { if (!args[i].isType()) - throw new ApplicationError("TypeApply expects types as arguments."); + throw unexpected("TypeApply expects types as arguments", args[i]); } } @@ -231,7 +231,7 @@ public class Tree { if (args != null) { for (int i = 0; i < args.length; i++) { if (!args[i].isTerm()) - throw new ApplicationError("Apply expects terms as arguments. Found: " + args[i].getClass()); + throw unexpected("Apply expects terms as arguments", args[i]); } } } @@ -240,7 +240,7 @@ public class Tree { */ public case Super(Tree tpe) { if (!tpe.isType()) { - throw new ApplicationError("Super expects type."); + throw unexpected("Super expects type", tpe); } } @@ -248,7 +248,7 @@ public class Tree { */ public case This(Tree qualifier) { if (!qualifier.isType()) - throw new ApplicationError("This expects type."); + throw unexpected("This expects type", qualifier); } /** designator @@ -256,7 +256,7 @@ public class Tree { public case Select(Tree qualifier, Name selector) { if (!qualifier.isTerm()) - throw new ApplicationError("Select expects term."); + throw unexpected("Select expects term", qualifier); } /** identifier @@ -273,7 +273,7 @@ public class Tree { */ public case SingletonType(Tree ref) { if (!ref.isTerm()) - throw new ApplicationError("SingletonType expects term."); + throw unexpected("SingletonType expects term", ref); } /** type selection @@ -281,7 +281,7 @@ public class Tree { public case SelectFromType(Tree qualifier, Name selector) { if (!qualifier.isType()) - throw new ApplicationError("SelectFromType expects type."); + throw unexpected("SelectFromType expects type", qualifier); assert selector.isTypeName(); } @@ -291,9 +291,9 @@ public class Tree { Tree restpe) { for (int i = 0; i < argtpes.length; i++) if (!argtpes[i].isType()) - throw new ApplicationError("FunType requires types as args."); + throw unexpected("FunType requires types as args", argtpes[i]); if (!restpe.isType()) - throw new ApplicationError("FunType requires type as result."); + throw unexpected("FunType requires type as result", restpe); } /** object type (~ Template) @@ -304,7 +304,7 @@ public class Tree { assert parents.length > 0; for (int i = 0; i < parents.length; i++) { if (!parents[i].isType()) - throw new ApplicationError("CompoundType requires types as parents."); + throw unexpected("CompoundType requires types as parents", parents[i]); } } } @@ -361,7 +361,7 @@ public class Tree { * Set symbol attached to the node, if possible. */ public Tree setSymbol(Symbol sym) { - throw new ApplicationError ("no settable symbol for node", this); + throw Debug.abort("no settable symbol for node", this); } /** @@ -755,5 +755,8 @@ public class Tree { return false; } } -} + private static Error unexpected(String message, Tree actual) { + return Debug.abort(message + "; found", actual); + } +} -- cgit v1.2.3