summaryrefslogtreecommitdiff
path: root/test/files/run/t8918-unary-ids.scala
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2014-10-17 01:45:50 -0700
committerSom Snytt <som.snytt@gmail.com>2015-02-08 12:21:16 -0800
commit33c568c029201b8bd76ace556ff3641db47d12fe (patch)
tree282b8e0294da1f05e5346c37243916ad3dfc236f /test/files/run/t8918-unary-ids.scala
parent178e8df9b6a91375a6162721a0cbc2d90bcc7451 (diff)
downloadscala-33c568c029201b8bd76ace556ff3641db47d12fe.tar.gz
scala-33c568c029201b8bd76ace556ff3641db47d12fe.tar.bz2
scala-33c568c029201b8bd76ace556ff3641db47d12fe.zip
SI-8918 Unary ids are plain ids
Allow +,-,!,~ to be used as unprefixed identifiers. As prefix operators, they must be followed by a simple expression, so otherwise, consume the id itself as the start of a simple expression.
Diffstat (limited to 'test/files/run/t8918-unary-ids.scala')
-rw-r--r--test/files/run/t8918-unary-ids.scala49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/files/run/t8918-unary-ids.scala b/test/files/run/t8918-unary-ids.scala
new file mode 100644
index 0000000000..1f29abe464
--- /dev/null
+++ b/test/files/run/t8918-unary-ids.scala
@@ -0,0 +1,49 @@
+
+
+import scala.tools.partest.SessionTest
+
+// Taking unary ids as plain
+object Test extends SessionTest {
+ def session =
+"""Type in expressions to have them evaluated.
+Type :help for more information.
+
+scala> val - = 42
+-: Int = 42
+
+scala> val i = -
+i: Int = 42
+
+scala> - { 42 }
+res0: Int = -42
+
+scala> - if (true) 1 else 2
+<console>:1: error: illegal start of simple expression
+ - if (true) 1 else 2
+ ^
+
+scala> - - 1
+<console>:1: error: ';' expected but integer literal found.
+ - - 1
+ ^
+
+scala> -.-(1)
+res1: Int = 41
+
+scala> -
+res2: Int = 42
+
+scala> - -
+res3: Int = -42
+
+scala> + -
+res4: Int = 42
+
+scala> object X { def -(i: Int) = 42 - i ; def f(g: Int => Int) = g(7) ; def j = f(-) }
+defined object X
+
+scala> X.j
+res5: Int = 35
+
+scala> :quit"""
+}