summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-03-12 19:11:24 -0700
committerPaul Phillips <paulp@improving.org>2013-03-12 19:11:24 -0700
commitccd1bc082630a3c4b4cfe2e64689b9e316ad8714 (patch)
treed75200b511d2717195aa5c4f42c4076c5f9fbf5b
parent52adf130409df57fd612a119e352345cf1c93979 (diff)
parenteb365f9158f29c61410affde21c8f3cd0c6db08f (diff)
downloadscala-ccd1bc082630a3c4b4cfe2e64689b9e316ad8714.tar.gz
scala-ccd1bc082630a3c4b4cfe2e64689b9e316ad8714.tar.bz2
scala-ccd1bc082630a3c4b4cfe2e64689b9e316ad8714.zip
Merge pull request #2227 from mergeconflict/2.10.x-SI-7132
SI-7132 - don't discard Unit type in interpreter
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ExprTyper.scala12
-rw-r--r--test/files/run/repl-colon-type.check21
-rw-r--r--test/files/run/repl-colon-type.scala4
3 files changed, 22 insertions, 15 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/ExprTyper.scala b/src/compiler/scala/tools/nsc/interpreter/ExprTyper.scala
index c4a672ac37..827ebe1678 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ExprTyper.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ExprTyper.scala
@@ -57,15 +57,13 @@ trait ExprTyper {
// Typing it with a lazy val would give us the right type, but runs
// into compiler bugs with things like existentials, so we compile it
// behind a def and strip the NullaryMethodType which wraps the expr.
- val line = "def " + name + " = {\n" + code + "\n}"
+ val line = "def " + name + " = " + code
interpretSynthetic(line) match {
case IR.Success =>
val sym0 = symbolOfTerm(name)
// drop NullaryMethodType
- val sym = sym0.cloneSymbol setInfo afterTyper(sym0.info.finalResultType)
- if (sym.info.typeSymbol eq UnitClass) NoSymbol
- else sym
+ sym0.cloneSymbol setInfo afterTyper(sym0.info.finalResultType)
case _ => NoSymbol
}
}
@@ -82,7 +80,11 @@ trait ExprTyper {
case _ => NoSymbol
}
}
- beQuietDuring(asExpr()) orElse beQuietDuring(asDefn())
+ def asError(): Symbol = {
+ interpretSynthetic(code)
+ NoSymbol
+ }
+ beSilentDuring(asExpr()) orElse beSilentDuring(asDefn()) orElse asError()
}
private var typeOfExpressionDepth = 0
diff --git a/test/files/run/repl-colon-type.check b/test/files/run/repl-colon-type.check
index 56ddd74375..0cb18e989a 100644
--- a/test/files/run/repl-colon-type.check
+++ b/test/files/run/repl-colon-type.check
@@ -4,12 +4,6 @@ Type :help for more information.
scala>
scala> :type List[1, 2, 3]
-<console>:2: error: identifier expected but integer literal found.
- List[1, 2, 3]
- ^
-<console>:3: error: ']' expected but '}' found.
- }
- ^
<console>:1: error: identifier expected but integer literal found.
List[1, 2, 3]
^
@@ -45,12 +39,9 @@ scala> :type lazy val f = 5
Int
scala> :type protected lazy val f = 5
-<console>:2: error: illegal start of statement (no modifiers allowed here)
- protected lazy val f = 5
- ^
<console>:5: error: lazy value f cannot be accessed in object $iw
Access to protected value f not permitted because
- enclosing object $eval in package $line19 is not a subclass of
+ enclosing object $eval in package $line13 is not a subclass of
object $iw where target is defined
lazy val $result = `f`
^
@@ -223,4 +214,14 @@ PolyType(
scala>
+scala> // SI-7132 - :type doesn't understand Unit
+
+scala> :type ()
+Unit
+
+scala> :type println("side effect!")
+Unit
+
+scala>
+
scala>
diff --git a/test/files/run/repl-colon-type.scala b/test/files/run/repl-colon-type.scala
index c055b215c2..8cf81a6afe 100644
--- a/test/files/run/repl-colon-type.scala
+++ b/test/files/run/repl-colon-type.scala
@@ -26,6 +26,10 @@ object Test extends ReplTest {
|:type -v Nil.combinations _
|:type -v def f[T <: AnyVal] = List[T]().combinations _
|:type -v def f[T, U >: T](x: T, y: List[U]) = x :: y
+ |
+ |// SI-7132 - :type doesn't understand Unit
+ |:type ()
+ |:type println("side effect!")
""".stripMargin
}