summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
diff options
context:
space:
mode:
authorHubert Plociniczak <hubert.plociniczak@epfl.ch>2011-09-07 12:17:54 +0000
committerHubert Plociniczak <hubert.plociniczak@epfl.ch>2011-09-07 12:17:54 +0000
commit620f339bbaadad57daa696007660bb887372e927 (patch)
treee9bf93cfa9d93a299f24cab28577900c36260438 /src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
parent596be479f1e527230f92db320642f77bae7e386d (diff)
downloadscala-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/typechecker/RefChecks.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 10918ecffa..c05a5e721e 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -1150,10 +1150,15 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
/* Check whether argument types conform to bounds of type parameters */
private def checkBounds(pre: Type, owner: Symbol, tparams: List[Symbol], argtps: List[Type], pos: Position): Unit =
- try typer.infer.checkBounds(pos, pre, owner, tparams, argtps, "")
+ try typer.infer.checkBounds(pos, pre, owner, tparams, argtps, "") match {
+ case Some(err) => err.emit(typer.context)
+ case _ => ()
+ }
catch {
case ex: TypeError =>
- unit.error(pos, ex.getMessage());
+ // checkBounds no longer throws errors (apart from Cyclic ones)
+ // so maybe it is safe to remove/simplify this catch?
+ unit.error(pos, ex.getMessage())
if (settings.explaintypes.value) {
val bounds = tparams map (tp => tp.info.instantiateTypeParams(tparams, argtps).bounds)
(argtps, bounds).zipped map ((targ, bound) => explainTypes(bound.lo, targ))
@@ -1310,7 +1315,13 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
case tpt@TypeTree() =>
if(tpt.original != null) {
tpt.original foreach {
- case dc@TypeTreeWithDeferredRefCheck() => applyRefchecksToAnnotations(dc.check()) // #2416
+ case dc@TypeTreeWithDeferredRefCheck() =>
+ dc.check() match {
+ case Left(err) =>
+ err.emit()
+ case Right(t) =>
+ applyRefchecksToAnnotations(t) // #2416
+ }
case _ =>
}
}
@@ -1474,8 +1485,11 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
if(tpt.original != null) {
tpt.original foreach {
case dc@TypeTreeWithDeferredRefCheck() =>
- transform(dc.check()) // #2416 -- only call transform to do refchecks, but discard results
- // tpt has the right type if the deferred checks are ok
+ dc.check() match {
+ case Left(err) => err.emit()
+ case Right(tree) => transform(tree) // #2416 -- only call transform to do refchecks, but discard results
+ // tpt has the right type if the deferred checks are ok
+ }
case _ =>
}
}
@@ -1551,7 +1565,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
result
} catch {
case ex: TypeError =>
- if (settings.debug.value) ex.printStackTrace();
+ if (settings.debug.value) ex.printStackTrace()
unit.error(tree.pos, ex.getMessage())
tree
} finally {