Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 7c1d114

Browse files
committed
Merge pull request scala#3208 from dotta/si-7548-on-2.10
askTypeAt returns the same type for full/ targeted typecheck (2.10.x)
2 parents da73950 + 02308c9 commit 7c1d114

File tree

7 files changed

+71
-9
lines changed

7 files changed

+71
-9
lines changed

src/compiler/scala/tools/nsc/interactive/Global.scala

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
238238
* @param result The transformed node
239239
*/
240240
override def signalDone(context: Context, old: Tree, result: Tree) {
241-
if (interruptsEnabled && analyzer.lockedCount == 0) {
241+
val canObserveTree = (
242+
interruptsEnabled
243+
&& analyzer.lockedCount == 0
244+
&& !context.bufferErrors // SI-7558 look away during exploratory typing in "silent mode"
245+
)
246+
if (canObserveTree) {
242247
if (context.unit.exists &&
243248
result.pos.isOpaqueRange &&
244249
(result.pos includes context.unit.targetPos)) {
@@ -249,14 +254,16 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
249254
}
250255
throw new TyperResult(located)
251256
}
252-
try {
253-
checkForMoreWork(old.pos)
254-
} catch {
255-
case ex: ValidateException => // Ignore, this will have been reported elsewhere
256-
debugLog("validate exception caught: "+ex)
257-
case ex: Throwable =>
258-
log.flush()
259-
throw ex
257+
else {
258+
try {
259+
checkForMoreWork(old.pos)
260+
} catch {
261+
case ex: ValidateException => // Ignore, this will have been reported elsewhere
262+
debugLog("validate exception caught: "+ex)
263+
case ex: Throwable =>
264+
log.flush()
265+
throw ex
266+
}
260267
}
261268
}
262269
}

test/files/presentation/t7548.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(x: Int)Unit
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import scala.tools.nsc.interactive.tests.InteractiveTest
2+
3+
object Test extends InteractiveTest {
4+
override protected def loadSources() { /* don't parse or typecheck sources */ }
5+
6+
import compiler._
7+
8+
override def runDefaultTests() {
9+
val res = new Response[Tree]
10+
val pos = compiler.rangePos(sourceFiles.head, 102,102,102)
11+
compiler.askTypeAt(pos, res)
12+
res.get match {
13+
case Left(tree) => compiler.ask(() => reporter.println(tree.tpe))
14+
case Right(ex) => reporter.println(ex)
15+
}
16+
}
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Foo {
2+
def foo(x: Int) = {}
3+
def foo(x: String) = {}
4+
def foo(x: Int, y: String) = {}
5+
6+
foo(2)
7+
}

test/files/presentation/t7548b.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Foo.this.I2BI(Foo.this.I).+: (other: Foo.BI.type)Unit
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import scala.tools.nsc.interactive.tests.InteractiveTest
2+
3+
object Test extends InteractiveTest {
4+
override protected def loadSources() { /* don't parse or typecheck sources */ }
5+
6+
import compiler._
7+
8+
override def runDefaultTests() {
9+
val res = new Response[Tree]
10+
val pos = compiler.rangePos(sourceFiles.head, 191, 191, 191) // +
11+
compiler.askTypeAt(pos, res)
12+
res.get match {
13+
case Left(tree) => compiler.ask(() => reporter.println(s"$tree: ${tree.tpe}"))
14+
case Right(ex) => reporter.println(ex)
15+
}
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import language._
2+
3+
object Foo {
4+
object I {
5+
def +(other: I.type) : Unit = ()
6+
}
7+
object BI {
8+
def +(other: BI.type): Unit = ()
9+
}
10+
implicit def I2BI(i: I.type): BI.type = BI
11+
I.+(BI)
12+
}

0 commit comments

Comments
 (0)