From e65321cb29758518573902041001d203d924c8bc Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sat, 10 Aug 2013 09:31:30 +0200 Subject: SI-7694 Add @uncheckedBounds to the library Followup to the previous commit that added the compiler support for opting out of bounds checking. With both pieces, we can test that the temporaries introduced by the named/default arguments transform don't trigger bounds violations. --- test/files/pos/t7694.scala | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/files/pos/t7694.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t7694.scala b/test/files/pos/t7694.scala new file mode 100644 index 0000000000..9852d5ec79 --- /dev/null +++ b/test/files/pos/t7694.scala @@ -0,0 +1,40 @@ +trait A +trait B + +trait L[A2, B2 <: A2] { + def bar(a: Any, b: Any) = 0 +} + +object Lub { + // use named args transforms to include TypeTree() in the AST before refchecks. + def foo(a: L[_, _], b: Any) = 0 + + foo(b = 0, a = if (true) (null: L[A, A]) else (null: L[B, B])) + + (if (true) (null: L[A, A]) else (null: L[B, B])).bar(b = 0, a = 0) +} + +/* +The LUB ends up as: + +TypeRef( + TypeSymbol( + abstract trait L#7038[A2#7039, B2#7040 <: A2#7039] extends AnyRef#2197 + + ) + args = List( + AbstractTypeRef( + AbstractType( + type _1#13680 >: A#7036 with B#7037 <: Object#1752 + ) + ) + AbstractTypeRef( + AbstractType( + type _2#13681 >: A#7036 with B#7037 <: Object#1752 + ) + ) + ) +) + +Note that type _2#13681 is *not* bound by _1#13680 +*/ -- cgit v1.2.3 From f91242c6959471b6c463538be8876a2cba29f3d3 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Sat, 15 Jun 2013 12:20:45 -0400 Subject: SI-7014 Annot arg may refer to annotated class's member This only reduces the crasher to a warning. --- .../scala/tools/nsc/symtab/classfile/ClassfileParser.scala | 11 ++++++++--- test/files/pos/t7014/ThreadSafety.java | 9 +++++++++ test/files/pos/t7014/ThreadSafetyLevel.java | 8 ++++++++ test/files/pos/t7014/t7014.scala | 4 ++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 test/files/pos/t7014/ThreadSafety.java create mode 100644 test/files/pos/t7014/ThreadSafetyLevel.java create mode 100644 test/files/pos/t7014/t7014.scala (limited to 'test/files/pos') diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 4e5204f283..2a8fe0428c 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -952,9 +952,14 @@ abstract class ClassfileParser { case ENUM_TAG => val t = pool.getType(index) val n = pool.getName(in.nextChar) - val s = t.typeSymbol.companionModule.info.decls.lookup(n) - assert(s != NoSymbol, t) - Some(LiteralAnnotArg(Constant(s))) + val module = t.typeSymbol.companionModule + val s = module.info.decls.lookup(n) + if (s != NoSymbol) Some(LiteralAnnotArg(Constant(s))) + else { + warning(s"""While parsing annotations in ${in.file}, could not find $n in enum $module.\nThis is likely due to an implementation restriction: an annotation argument cannot refer to a member of the annotated class (SI-7014).""") + None + } + case ARRAY_TAG => val arr = new ArrayBuffer[ClassfileAnnotArg]() var hasError = false diff --git a/test/files/pos/t7014/ThreadSafety.java b/test/files/pos/t7014/ThreadSafety.java new file mode 100644 index 0000000000..ed508804e3 --- /dev/null +++ b/test/files/pos/t7014/ThreadSafety.java @@ -0,0 +1,9 @@ +package t7014; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) // must be exactly RUNTIME retention (those we parse) +public @interface ThreadSafety { + ThreadSafetyLevel level(); +} \ No newline at end of file diff --git a/test/files/pos/t7014/ThreadSafetyLevel.java b/test/files/pos/t7014/ThreadSafetyLevel.java new file mode 100644 index 0000000000..4df1dc787a --- /dev/null +++ b/test/files/pos/t7014/ThreadSafetyLevel.java @@ -0,0 +1,8 @@ +package t7014; // package needed due to other bug in scalac's java parser + +// since we parse eagerly, we have not yet parsed the classfile when parsing the annotation, +// and on doing so, fail to find a symbol for the COMPLETELY_THREADSAFE reference +// from the annotation's argument to the enum's member +// for now, let's just not crash -- should implement lazy completing at some point +@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) +public enum ThreadSafetyLevel { COMPLETELY_THREADSAFE } diff --git a/test/files/pos/t7014/t7014.scala b/test/files/pos/t7014/t7014.scala new file mode 100644 index 0000000000..faec4c7740 --- /dev/null +++ b/test/files/pos/t7014/t7014.scala @@ -0,0 +1,4 @@ +package t7014 + +import ThreadSafetyLevel.COMPLETELY_THREADSAFE // refer to annotation so it gets parsed + \ No newline at end of file -- cgit v1.2.3 From 42e0f73311cfaf0883b85a1a41f400c3eb3cae96 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Fri, 16 Aug 2013 11:30:33 +0200 Subject: SI-7716 Exclude patmat synthetics from bounds checking Consider this pattern match translation, that occurs *before* refchecks: scala> val e: java.lang.Enum[_] = java.util.concurrent.TimeUnit.SECONDS scala> e match { case x => x } :9: error: type arguments [_$1] do not conform to class Enum's type parameter bounds [E <: Enum[E]] e match { case x => x } ^ [[syntax trees at end of refchecks]] // package $line5 { case val x1: Enum[_$1] = $line3.$read.$iw.$iw.e; case4(){ matchEnd3(x1) }; matchEnd3(x: Enum[_$1]){ x } RefChecks turns a blind eye to the non-conformant type `Enum[_$1]` in the label defs because of `65340ed4ad2e`. (Incidentally, that is far too broad, as I've noted in SI-7756.) This commit extends this exception to cover the synthetic ValDef `x1`. Commit log watchers might notice the similarities to SI-7694. --- src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 4 +++- test/files/pos/t7716.scala | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/files/pos/t7716.scala (limited to 'test/files/pos') diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index db899b44f9..09c4878b2f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1826,9 +1826,11 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans case LabelDef(_, _, _) if treeInfo.hasSynthCaseSymbol(result) => val old = inPattern inPattern = true - val res = deriveLabelDef(result)(transform) + val res = deriveLabelDef(result)(transform) // TODO SI-7756 Too broad! The code from the original case body should be fully refchecked! inPattern = old res + case ValDef(_, _, _, _) if treeInfo.hasSynthCaseSymbol(result) => + deriveValDef(result)(transform) // SI-7716 Don't refcheck the tpt of the synthetic val that holds the selector. case _ => super.transform(result) } diff --git a/test/files/pos/t7716.scala b/test/files/pos/t7716.scala new file mode 100644 index 0000000000..40117051ed --- /dev/null +++ b/test/files/pos/t7716.scala @@ -0,0 +1,16 @@ +object Test { + def test: Unit = { + val e: java.lang.Enum[_] = java.util.concurrent.TimeUnit.SECONDS + e match { case x => println(x) } + + + trait TA[X <: CharSequence] + val ta: TA[_] = new TA[String] {} + + ta match { + case _ => println("hi") + } + + def f(ta: TA[_]) = ta match { case _ => "hi" } + } +} -- cgit v1.2.3 From bc6d4b5c1d6746528fd442d8504f30909d7e6067 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 21 Aug 2013 12:05:23 +0200 Subject: SI-7486 More tests for cycles triggered by implicit search Moved an existing test from `pending` to `pos`. Not sure why it was moved to `pending` in the first place. Adds a new test distilled from building Scalaz with 2.10.3-RC1. --- test/files/pos/t7486-named.scala | 8 ++++++++ test/files/pos/t7486.scala | 8 ++++++++ test/pending/pos/t7486.scala | 8 -------- 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 test/files/pos/t7486-named.scala create mode 100644 test/files/pos/t7486.scala delete mode 100644 test/pending/pos/t7486.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t7486-named.scala b/test/files/pos/t7486-named.scala new file mode 100644 index 0000000000..253293e5f1 --- /dev/null +++ b/test/files/pos/t7486-named.scala @@ -0,0 +1,8 @@ + +object Test { + def fold(empty: Any) = () + implicit val notAnnotatedImplicit = new { + fold(empty = 0) + def empty[A]: Any = ??? + } +} diff --git a/test/files/pos/t7486.scala b/test/files/pos/t7486.scala new file mode 100644 index 0000000000..6dd7f4c4ac --- /dev/null +++ b/test/files/pos/t7486.scala @@ -0,0 +1,8 @@ +object Test{ + var locker = 0 + // remove implicit, or change to `locker = locker + 1` to make it compile. + implicit val davyJones0 = { + locker += 0 + 0 + } +} diff --git a/test/pending/pos/t7486.scala b/test/pending/pos/t7486.scala deleted file mode 100644 index 6dd7f4c4ac..0000000000 --- a/test/pending/pos/t7486.scala +++ /dev/null @@ -1,8 +0,0 @@ -object Test{ - var locker = 0 - // remove implicit, or change to `locker = locker + 1` to make it compile. - implicit val davyJones0 = { - locker += 0 - 0 - } -} -- cgit v1.2.3 From ed34bcb651ed9911d48c88d9f1e6b3adfd88a2f8 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Fri, 23 Aug 2013 11:14:09 +0200 Subject: SI-942 A test case, five years adrift. I'm looking at the changes made in 47f35b587, which prevented cyclic errors in class file parsing. That fix is insufficient for, or otherwise complicit in, SI-7778, for which I've enclosed a pending test. --- test/files/pos/t942/Amount_1.java | 5 +++++ test/files/pos/t942/Test_2.scala | 3 +++ test/pending/pos/t7778/Foo_1.java | 6 ++++++ test/pending/pos/t7778/Test_2.scala | 3 +++ 4 files changed, 17 insertions(+) create mode 100644 test/files/pos/t942/Amount_1.java create mode 100644 test/files/pos/t942/Test_2.scala create mode 100644 test/pending/pos/t7778/Foo_1.java create mode 100644 test/pending/pos/t7778/Test_2.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t942/Amount_1.java b/test/files/pos/t942/Amount_1.java new file mode 100644 index 0000000000..d9d37d127b --- /dev/null +++ b/test/files/pos/t942/Amount_1.java @@ -0,0 +1,5 @@ +import java.util.concurrent.Callable; + +public abstract class Amount_1 extends Object + implements Callable> { +} diff --git a/test/files/pos/t942/Test_2.scala b/test/files/pos/t942/Test_2.scala new file mode 100644 index 0000000000..3cc84dae3c --- /dev/null +++ b/test/files/pos/t942/Test_2.scala @@ -0,0 +1,3 @@ +abstract class Foo { + val x: Amount_1[Foo] +} diff --git a/test/pending/pos/t7778/Foo_1.java b/test/pending/pos/t7778/Foo_1.java new file mode 100644 index 0000000000..65431ffd46 --- /dev/null +++ b/test/pending/pos/t7778/Foo_1.java @@ -0,0 +1,6 @@ +import java.util.concurrent.Callable; + +public abstract class Foo_1 implements Callable.Inner> { + public abstract class Inner { + } +} diff --git a/test/pending/pos/t7778/Test_2.scala b/test/pending/pos/t7778/Test_2.scala new file mode 100644 index 0000000000..306303a99e --- /dev/null +++ b/test/pending/pos/t7778/Test_2.scala @@ -0,0 +1,3 @@ +class Test { + null: Foo_1[_] +} -- cgit v1.2.3