summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorMirco Dotta <mirco.dotta@typesafe.com>2013-11-22 11:55:19 +0100
committerMirco Dotta <mirco.dotta@typesafe.com>2013-12-02 10:17:41 +0100
commitb7509c922f78624a9eba88c3c64054e0d217ecea (patch)
tree37d77ad18829992f72fb127c01d84606a641ced8 /src/compiler
parentda7395016ca8410fbabf5418288f7275ccaf17a8 (diff)
downloadscala-b7509c922f78624a9eba88c3c64054e0d217ecea.tar.gz
scala-b7509c922f78624a9eba88c3c64054e0d217ecea.tar.bz2
scala-b7509c922f78624a9eba88c3c64054e0d217ecea.zip
SI-7548 askTypeAt returns the same type whether the source was fully or targeted type-checked
When asking for targeted typecheck, the located tree may have overloaded types is the source isn't yet fully typechecked (e.g., a select tree for an overloaded method). This is problematic as it can lead to unknown 'hovers', broken hyperlinking that suddenly starts working, unresolved ScalaDoc comments, and similar, in the Scala IDE. With this commit we are hardening the contract of `askTypeAt` to return the same type whether the file was fully type-checked or targeted type-checked. This is done by preventing the typechecker to stop too early if the `located` tree has an overloaded type. Furthermore, I'm assuming that if `located.tpe` is of type `OverloadedType`, by letting the compiler carry-on the typechecking, the `located.tpe` will eventually be resolved to a non-overloaded type. Said otherwise, I expect the targeted typechecking will always terminate (if my reasoning isn't sound, please say so). The test provided with this commit demonstrates the new behavior (the position used to execute the test is resolved to the `foo` method's call). In fact, before this commit, executing the test returned the following: (x: Int, y: String)Unit <and> (x: String)Unit <and> (x: Int)Unit Showing that the tree's type is an overloaded type. The ambiguity is fixed by this commit, and in fact the test's output is now: (x: Int)Unit
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/interactive/Global.scala23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala
index 49f6cb2373..b4e8170b19 100644
--- a/src/compiler/scala/tools/nsc/interactive/Global.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Global.scala
@@ -247,16 +247,21 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
println("something's wrong: no "+context.unit+" in "+result+result.pos)
located = result
}
- throw new TyperResult(located)
+ located.tpe match {
+ case _: OverloadedType => ()
+ case _ => throw new TyperResult(located)
+ }
}
- try {
- checkForMoreWork(old.pos)
- } catch {
- case ex: ValidateException => // Ignore, this will have been reported elsewhere
- debugLog("validate exception caught: "+ex)
- case ex: Throwable =>
- log.flush()
- throw ex
+ else {
+ try {
+ checkForMoreWork(old.pos)
+ } catch {
+ case ex: ValidateException => // Ignore, this will have been reported elsewhere
+ debugLog("validate exception caught: "+ex)
+ case ex: Throwable =>
+ log.flush()
+ throw ex
+ }
}
}
}