summaryrefslogtreecommitdiff
path: root/test/files/neg
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-12-20 13:19:19 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-12-20 13:19:19 +1000
commit079e8dc61704a768792c6b210a5b0cd25522ee55 (patch)
tree37154f37a745c9c7535cbe0a7f6cef486beb5870 /test/files/neg
parent56fb9172756d95ef903c36efcf54f1ae95c64b4b (diff)
parent23548c4301e48cb69f05cd01ceba418dc9c36d6c (diff)
downloadscala-079e8dc61704a768792c6b210a5b0cd25522ee55.tar.gz
scala-079e8dc61704a768792c6b210a5b0cd25522ee55.tar.bz2
scala-079e8dc61704a768792c6b210a5b0cd25522ee55.zip
Merge remote-tracking branch 'origin/2.11.x' into merge/2.11.x-to-2.12.x-20161220
Conflicts: bincompat-backward.whitelist.conf build.xml src/compiler/scala/tools/nsc/typechecker/Typers.scala src/library/scala/collection/immutable/NumericRange.scala
Diffstat (limited to 'test/files/neg')
-rw-r--r--test/files/neg/t0903.check1
-rw-r--r--test/files/neg/t1215.check1
-rw-r--r--test/files/neg/t3236-neg.check34
-rw-r--r--test/files/neg/t3236-neg/AnnotationTest.scala17
-rw-r--r--test/files/neg/t3236-neg/BooleanAnnotation.java7
-rw-r--r--test/files/neg/t3236-neg/Constants.java25
-rw-r--r--test/files/neg/t3236-neg/IntAnnotation.java7
-rw-r--r--test/files/neg/t3236-neg/ShortAnnotation.java7
-rw-r--r--test/files/neg/t3236-neg/StringAnnotation.java7
-rw-r--r--test/files/neg/t8763.check6
-rw-r--r--test/files/neg/t8763.scala11
-rw-r--r--test/files/neg/t9834.check9
-rw-r--r--test/files/neg/t9834.scala6
13 files changed, 138 insertions, 0 deletions
diff --git a/test/files/neg/t0903.check b/test/files/neg/t0903.check
index 2dd05cd3ee..f9dc28bf16 100644
--- a/test/files/neg/t0903.check
+++ b/test/files/neg/t0903.check
@@ -1,4 +1,5 @@
t0903.scala:3: error: value += is not a member of Int
+ Expression does not convert to assignment because receiver is not assignable.
x += 1
^
t0903.scala:4: error: reassignment to val
diff --git a/test/files/neg/t1215.check b/test/files/neg/t1215.check
index 1f9dd6bf38..4cbd0d85f3 100644
--- a/test/files/neg/t1215.check
+++ b/test/files/neg/t1215.check
@@ -1,4 +1,5 @@
t1215.scala:2: error: value += is not a member of Int
+ Expression does not convert to assignment because receiver is not assignable.
val x = 1 += 1
^
one error found
diff --git a/test/files/neg/t3236-neg.check b/test/files/neg/t3236-neg.check
new file mode 100644
index 0000000000..ef28574d45
--- /dev/null
+++ b/test/files/neg/t3236-neg.check
@@ -0,0 +1,34 @@
+AnnotationTest.scala:3: error: annotation argument needs to be a constant; found: Constants.ConstIdent
+ @IntAnnotation(Constants.ConstIdent)
+ ^
+AnnotationTest.scala:4: error: annotation argument needs to be a constant; found: Constants.ConstSelect
+ @IntAnnotation(Constants.ConstSelect)
+ ^
+AnnotationTest.scala:6: error: annotation argument needs to be a constant; found: Constants.ConstOpExpr1
+ @IntAnnotation(Constants.ConstOpExpr1)
+ ^
+AnnotationTest.scala:7: error: annotation argument needs to be a constant; found: Constants.ConstOpExpr2
+ @IntAnnotation(Constants.ConstOpExpr2)
+ ^
+AnnotationTest.scala:8: error: annotation argument needs to be a constant; found: Constants.ConstOpExpr3
+ @BooleanAnnotation(Constants.ConstOpExpr3)
+ ^
+AnnotationTest.scala:9: error: annotation argument needs to be a constant; found: Constants.ConstOpExpr4
+ @IntAnnotation(Constants.ConstOpExpr4)
+ ^
+AnnotationTest.scala:10: error: annotation argument needs to be a constant; found: Constants.NonFinalConst
+ @IntAnnotation(Constants.NonFinalConst)
+ ^
+AnnotationTest.scala:11: error: value NonStaticConst is not a member of object Constants
+ @IntAnnotation(Constants.NonStaticConst)
+ ^
+AnnotationTest.scala:12: error: value NonConst is not a member of object Constants
+ @IntAnnotation(Constants.NonConst)
+ ^
+AnnotationTest.scala:13: error: annotation argument needs to be a constant; found: Constants.ConstCastExpr
+ @ShortAnnotation(Constants.ConstCastExpr)
+ ^
+AnnotationTest.scala:15: error: annotation argument needs to be a constant; found: Constants.StringAdd
+ @StringAnnotation(Constants.StringAdd)
+ ^
+11 errors found
diff --git a/test/files/neg/t3236-neg/AnnotationTest.scala b/test/files/neg/t3236-neg/AnnotationTest.scala
new file mode 100644
index 0000000000..aec2a99020
--- /dev/null
+++ b/test/files/neg/t3236-neg/AnnotationTest.scala
@@ -0,0 +1,17 @@
+trait AnnotationTest {
+ @IntAnnotation(Constants.ConstInt) // ok
+ @IntAnnotation(Constants.ConstIdent)
+ @IntAnnotation(Constants.ConstSelect)
+ @IntAnnotation(Constants.NegatedInt) // ok
+ @IntAnnotation(Constants.ConstOpExpr1)
+ @IntAnnotation(Constants.ConstOpExpr2)
+ @BooleanAnnotation(Constants.ConstOpExpr3)
+ @IntAnnotation(Constants.ConstOpExpr4)
+ @IntAnnotation(Constants.NonFinalConst)
+ @IntAnnotation(Constants.NonStaticConst)
+ @IntAnnotation(Constants.NonConst)
+ @ShortAnnotation(Constants.ConstCastExpr)
+ @StringAnnotation(Constants.ConstString) // ok
+ @StringAnnotation(Constants.StringAdd)
+ def test: Unit
+} \ No newline at end of file
diff --git a/test/files/neg/t3236-neg/BooleanAnnotation.java b/test/files/neg/t3236-neg/BooleanAnnotation.java
new file mode 100644
index 0000000000..7e57a5e0db
--- /dev/null
+++ b/test/files/neg/t3236-neg/BooleanAnnotation.java
@@ -0,0 +1,7 @@
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface BooleanAnnotation {
+ boolean value();
+}
diff --git a/test/files/neg/t3236-neg/Constants.java b/test/files/neg/t3236-neg/Constants.java
new file mode 100644
index 0000000000..01d2d70dd7
--- /dev/null
+++ b/test/files/neg/t3236-neg/Constants.java
@@ -0,0 +1,25 @@
+// https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.28
+public class Constants {
+ public static final int ConstInt = 1;
+
+ public static final int ConstIdent = ConstInt;
+ public static final int ConstSelect = Constants.ConstInt;
+
+ // this is a known limitation in scala's javac parser for constants, it will be treated as -1.
+ // the java compiler will flag an error.
+ public static final int NegatedInt = !1;
+
+ public static final int ConstOpExpr1 = 1 + 2;
+ public static final int ConstOpExpr2 = 1 << 2;
+ public static final boolean ConstOpExpr3 = 1 == 1;
+ public static final int ConstOpExpr4 = true ? 1 : 2;
+
+ public static int NonFinalConst = 1;
+ public final int NonStaticConst = 1;
+ public int NonConst = 1;
+
+ public static final short ConstCastExpr = (short)(1*2*3*4*5*6);
+
+ public static final String ConstString = "a";
+ public static final String StringAdd = "a" + 1;
+}
diff --git a/test/files/neg/t3236-neg/IntAnnotation.java b/test/files/neg/t3236-neg/IntAnnotation.java
new file mode 100644
index 0000000000..2ffad8890c
--- /dev/null
+++ b/test/files/neg/t3236-neg/IntAnnotation.java
@@ -0,0 +1,7 @@
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface IntAnnotation {
+ int value();
+}
diff --git a/test/files/neg/t3236-neg/ShortAnnotation.java b/test/files/neg/t3236-neg/ShortAnnotation.java
new file mode 100644
index 0000000000..f0a35892c7
--- /dev/null
+++ b/test/files/neg/t3236-neg/ShortAnnotation.java
@@ -0,0 +1,7 @@
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ShortAnnotation {
+ short value();
+}
diff --git a/test/files/neg/t3236-neg/StringAnnotation.java b/test/files/neg/t3236-neg/StringAnnotation.java
new file mode 100644
index 0000000000..0fdc1ead38
--- /dev/null
+++ b/test/files/neg/t3236-neg/StringAnnotation.java
@@ -0,0 +1,7 @@
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface StringAnnotation {
+ String value();
+}
diff --git a/test/files/neg/t8763.check b/test/files/neg/t8763.check
new file mode 100644
index 0000000000..4659e57be6
--- /dev/null
+++ b/test/files/neg/t8763.check
@@ -0,0 +1,6 @@
+t8763.scala:9: error: type mismatch;
+ found : Char
+ required: String
+ names_times(fields(0)) += fields(1).toLong
+ ^
+one error found
diff --git a/test/files/neg/t8763.scala b/test/files/neg/t8763.scala
new file mode 100644
index 0000000000..08ce1b471a
--- /dev/null
+++ b/test/files/neg/t8763.scala
@@ -0,0 +1,11 @@
+
+import collection.mutable
+
+object Foo {
+ def bar() {
+ val names_times = mutable.Map[String, mutable.Set[Long]]()
+ val line = ""
+ val Array(fields) = line.split("\t")
+ names_times(fields(0)) += fields(1).toLong
+ }
+}
diff --git a/test/files/neg/t9834.check b/test/files/neg/t9834.check
new file mode 100644
index 0000000000..d07eb7f155
--- /dev/null
+++ b/test/files/neg/t9834.check
@@ -0,0 +1,9 @@
+t9834.scala:5: error: value += is not a member of Int
+ Expression does not convert to assignment because:
+ type mismatch;
+ found : String
+ required: Int
+ expansion: x.update(x.apply().+("42"))
+ x() += "42"
+ ^
+one error found
diff --git a/test/files/neg/t9834.scala b/test/files/neg/t9834.scala
new file mode 100644
index 0000000000..1ecda7a2b8
--- /dev/null
+++ b/test/files/neg/t9834.scala
@@ -0,0 +1,6 @@
+
+object x { def apply() = 42 ; def update(i: Int) = () }
+
+trait Test {
+ x() += "42"
+}