diff options
author | Hubert Plociniczak <hubert.plociniczak@epfl.ch> | 2011-09-07 12:17:54 +0000 |
---|---|---|
committer | Hubert Plociniczak <hubert.plociniczak@epfl.ch> | 2011-09-07 12:17:54 +0000 |
commit | 620f339bbaadad57daa696007660bb887372e927 (patch) | |
tree | e9bf93cfa9d93a299f24cab28577900c36260438 /src/compiler/scala/tools/nsc/ast/TreeGen.scala | |
parent | 596be479f1e527230f92db320642f77bae7e386d (diff) | |
download | scala-620f339bbaadad57daa696007660bb887372e927.tar.gz scala-620f339bbaadad57daa696007660bb887372e927.tar.bz2 scala-620f339bbaadad57daa696007660bb887372e927.zip |
First refactoring related to Error trees.
There are no more direct calls to context.error from Typers and Infer,
so more work needs to be done to finish it for Implicits and Namers.
I am pushing it to trunk so that all of you can share my pain (and
complain). Please do not add any more context.error randomly in that
code, instead deal with it appropriately (by creating specific error
tree).
I was trying to be as informative when it comes to error tree names
as possible, but if you feel like changing names to something more
appropriate then feel free to do so. When it comes to printing error
messages I tried to follow test suite as closily as possible but
obviously there were few changes to some tests (mostly positive, I
believe).
On my machine performance drawback was neglible but I am working on more
aggressive caching to reduce the penalty of containsError() calls even
more. Any suggestions welcome.
At the moment the code supports both styles i.e. throwing type errors
for the cases that are not yet handled and generating error trees. But
in the future we will drop the former completely (apart from cyclic
errors which can pop up almost everywhere).
Review by odersky, extempore and anyone who feels like it.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/TreeGen.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeGen.scala | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala index acca7dac7d..ee0b28b02f 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala @@ -191,15 +191,21 @@ abstract class TreeGen extends reflect.internal.TreeGen { * symbol to its packed type, and an function for creating Idents * which refer to it. */ - private def mkPackedValDef(expr: Tree, owner: Symbol, name: Name): (ValDef, () => Ident) = { - val packedType = typer.packedType(expr, owner) + private def mkPackedValDef(expr: Tree, owner: Symbol, name: Name): (Tree, () => Ident) = { + val (packedType, errs) = typer.packedType(expr, owner) + // TODO ensure that they don't throw errors? + errs.foreach(_.emit(typer.context)) val sym = ( owner.newValue(expr.pos.makeTransparent, name) setFlag SYNTHETIC setInfo packedType ) - (ValDef(sym, expr), () => Ident(sym) setPos sym.pos.focus setType expr.tpe) + val identFn = () => Ident(sym) setPos sym.pos.focus setType expr.tpe + if (errs.isEmpty) + (ValDef(sym, expr), identFn) + else + (analyzer.PendingErrors(errs), identFn) } /** Used in situations where you need to access value of an expression several times @@ -218,7 +224,7 @@ abstract class TreeGen extends reflect.internal.TreeGen { } def evalOnceAll(exprs: List[Tree], owner: Symbol, unit: CompilationUnit)(within: (List[() => Tree]) => Tree): Tree = { - val vdefs = new ListBuffer[ValDef] + val vdefs = new ListBuffer[Tree] val exprs1 = new ListBuffer[() => Tree] val used = new Array[Boolean](exprs.length) var i = 0 |