summaryrefslogtreecommitdiff
path: root/test/files
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 /test/files
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 'test/files')
-rw-r--r--test/files/presentation/t7548.check1
-rw-r--r--test/files/presentation/t7548/Test.scala17
-rw-r--r--test/files/presentation/t7548/src/Foo.scala7
3 files changed, 25 insertions, 0 deletions
diff --git a/test/files/presentation/t7548.check b/test/files/presentation/t7548.check
new file mode 100644
index 0000000000..5bfb0d27fe
--- /dev/null
+++ b/test/files/presentation/t7548.check
@@ -0,0 +1 @@
+(x: Int)Unit
diff --git a/test/files/presentation/t7548/Test.scala b/test/files/presentation/t7548/Test.scala
new file mode 100644
index 0000000000..94a6048056
--- /dev/null
+++ b/test/files/presentation/t7548/Test.scala
@@ -0,0 +1,17 @@
+import scala.tools.nsc.interactive.tests.InteractiveTest
+
+object Test extends InteractiveTest {
+ override protected def loadSources() { /* don't parse or typecheck sources */ }
+
+ import compiler._
+
+ override def runDefaultTests() {
+ val res = new Response[Tree]
+ val pos = compiler.rangePos(sourceFiles.head, 102,102,102)
+ compiler.askTypeAt(pos, res)
+ res.get match {
+ case Left(tree) => compiler.ask(() => reporter.println(tree.tpe))
+ case Right(ex) => reporter.println(ex)
+ }
+ }
+}
diff --git a/test/files/presentation/t7548/src/Foo.scala b/test/files/presentation/t7548/src/Foo.scala
new file mode 100644
index 0000000000..cc997f6e5f
--- /dev/null
+++ b/test/files/presentation/t7548/src/Foo.scala
@@ -0,0 +1,7 @@
+object Foo {
+ def foo(x: Int) = {}
+ def foo(x: String) = {}
+ def foo(x: Int, y: String) = {}
+
+ foo(2)
+} \ No newline at end of file