From ce74bb00603f23087fbd3b0fe2870f09d73bb676 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sat, 25 May 2013 22:57:33 +0200 Subject: [nomaster] SI-7519 Less brutal attribute resetting in adapt fallback Prefers `resetLocalAttrs` over `resetAllAttrs`. The latter loses track of which enclosing class of the given name is referenced by a `This` node which prefixes the an applied implicit view. The code that `resetAllAttrs` originally landed in: https://github.com/scala/scala/commit/d4c63b#L6R804 Cherry picked from 433880e91cba9e1e926e9fcbf04ecd4aeb1d73eb Conflicts: src/compiler/scala/tools/nsc/typechecker/Typers.scala --- test/files/neg/t7519.check | 7 +++++++ test/files/neg/t7519.scala | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/files/neg/t7519.check create mode 100644 test/files/neg/t7519.scala (limited to 'test/files') diff --git a/test/files/neg/t7519.check b/test/files/neg/t7519.check new file mode 100644 index 0000000000..164d67f595 --- /dev/null +++ b/test/files/neg/t7519.check @@ -0,0 +1,7 @@ +t7519.scala:5: error: could not find implicit value for parameter nada: Nothing + locally(0 : String) // was: "value conversion is not a member of C.this.C" + ^ +t7519.scala:15: error: could not find implicit value for parameter nada: Nothing + locally(0 : String) // was: "value conversion is not a member of U" + ^ +two errors found diff --git a/test/files/neg/t7519.scala b/test/files/neg/t7519.scala new file mode 100644 index 0000000000..aea0f35d8e --- /dev/null +++ b/test/files/neg/t7519.scala @@ -0,0 +1,18 @@ +class C { + implicit def conversion(m: Int)(implicit nada: Nothing): String = ??? + + class C { // rename class to get correct error, can't find implicit: Nothing. + locally(0 : String) // was: "value conversion is not a member of C.this.C" + } +} + +object Test2 { + trait T; trait U + new T { + implicit def conversion(m: Int)(implicit nada: Nothing): String = ??? + + new U { // nested anonymous classes also share a name. + locally(0 : String) // was: "value conversion is not a member of U" + } + } +} -- cgit v1.2.3 From 50c8b39ec4e795b6de7b8ebeb6e20bf5c4b7f9e0 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Fri, 18 Oct 2013 16:39:26 -0400 Subject: SI-7519: Additional test case covering sbt/sbt#914 (cherry picked from commit e72c32db03b44d6eaf1c1872765a578c5445e15f) --- test/files/neg/t7519-b.check | 4 ++++ test/files/neg/t7519-b/Mac_1.scala | 14 ++++++++++++++ test/files/neg/t7519-b/Use_2.scala | 8 ++++++++ 3 files changed, 26 insertions(+) create mode 100644 test/files/neg/t7519-b.check create mode 100644 test/files/neg/t7519-b/Mac_1.scala create mode 100644 test/files/neg/t7519-b/Use_2.scala (limited to 'test/files') diff --git a/test/files/neg/t7519-b.check b/test/files/neg/t7519-b.check new file mode 100644 index 0000000000..ad554b8633 --- /dev/null +++ b/test/files/neg/t7519-b.check @@ -0,0 +1,4 @@ +Use_2.scala:6: error: No implicit view available from String => K. + val x: Q = ex.Mac.mac("asdf") + ^ +one error found diff --git a/test/files/neg/t7519-b/Mac_1.scala b/test/files/neg/t7519-b/Mac_1.scala new file mode 100644 index 0000000000..55b583d24b --- /dev/null +++ b/test/files/neg/t7519-b/Mac_1.scala @@ -0,0 +1,14 @@ +// get expected error message without package declaration +package ex + +import scala.language.experimental.macros +import scala.reflect.macros._ + +object IW { + def foo(a: String): String = ??? +} +object Mac { + def mac(s: String): String = macro macImpl + def macImpl(c: Context)(s: c.Expr[String]): c.Expr[String] = + c.universe.reify(IW.foo(s.splice)) +} diff --git a/test/files/neg/t7519-b/Use_2.scala b/test/files/neg/t7519-b/Use_2.scala new file mode 100644 index 0000000000..413e40e25e --- /dev/null +++ b/test/files/neg/t7519-b/Use_2.scala @@ -0,0 +1,8 @@ +trait Q +trait K + +object Use { + implicit def cd[T](p: T)(implicit ev: T => K): Q = ??? + val x: Q = ex.Mac.mac("asdf") +} + -- cgit v1.2.3 From 075f6f260ccfba83b118c308195d1ede2e66ad18 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 4 Nov 2013 16:51:20 -0800 Subject: SI-6546 InnerClasses attribute refers to absent class At issue is that the optimizer would eliminate closure classes completely, then neglect to eliminate those classes from the container's InnerClasses attribute. This breaks tooling which expects those entries to correspond to real classes. The code change is essentially mgarcia's - I minimized it and put the caches in perRunCaches, and added the test case which verifies that after being compiled under -optimise, there are no inner classes. Before/after: 7,8d6 < InnerClasses: < public final #22; //class A_1$$anonfun$f$1 37,45c35,40 < #21 = Utf8 A_1$$anonfun$f$1 < #22 = Class #21 // A_1$$anonfun$f$1 < #23 = Utf8 Code --- > #21 = Utf8 Code --- src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala | 4 +++- .../scala/tools/nsc/backend/opt/DeadCodeElimination.scala | 8 +++++++- test/files/run/t6546.flags | 1 + test/files/run/t6546/A_1.scala | 6 ++++++ test/files/run/t6546/B_2.scala | 8 ++++++++ 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/files/run/t6546.flags create mode 100644 test/files/run/t6546/A_1.scala create mode 100644 test/files/run/t6546/B_2.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala index 7c46d648fe..97140aca2e 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala @@ -86,6 +86,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM { if (settings.Xdce.value) for ((sym, cls) <- icodes.classes if inliner.isClosureClass(sym) && !deadCode.liveClosures(sym)) { log(s"Optimizer eliminated ${sym.fullNameString}") + deadCode.elidedClosures += sym icodes.classes -= sym } @@ -624,7 +625,8 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM { innerClassBuffer += m } - val allInners: List[Symbol] = innerClassBuffer.toList + val allInners: List[Symbol] = innerClassBuffer.toList filterNot deadCode.elidedClosures + if (allInners.nonEmpty) { debuglog(csym.fullName('.') + " contains " + allInners.size + " inner classes.") diff --git a/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala b/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala index 1beed3f420..db56f61f16 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala @@ -40,7 +40,13 @@ abstract class DeadCodeElimination extends SubComponent { } /** closures that are instantiated at least once, after dead code elimination */ - val liveClosures: mutable.Set[Symbol] = new mutable.HashSet() + val liveClosures = perRunCaches.newSet[Symbol]() + + /** closures that are eliminated, populated by GenASM.AsmPhase.run() + * these class symbols won't have a .class physical file, thus shouldn't be included in InnerClasses JVM attribute, + * otherwise some tools get confused or slow (SI-6546) + * */ + val elidedClosures = perRunCaches.newSet[Symbol]() /** Remove dead code. */ diff --git a/test/files/run/t6546.flags b/test/files/run/t6546.flags new file mode 100644 index 0000000000..eb4d19bcb9 --- /dev/null +++ b/test/files/run/t6546.flags @@ -0,0 +1 @@ +-optimise \ No newline at end of file diff --git a/test/files/run/t6546/A_1.scala b/test/files/run/t6546/A_1.scala new file mode 100644 index 0000000000..bd086c08f8 --- /dev/null +++ b/test/files/run/t6546/A_1.scala @@ -0,0 +1,6 @@ +final class Opt { + @inline def getOrElse(x: => String): String = "" +} +class A_1 { + def f(x: Opt): String = x getOrElse null +} diff --git a/test/files/run/t6546/B_2.scala b/test/files/run/t6546/B_2.scala new file mode 100644 index 0000000000..64ec966f75 --- /dev/null +++ b/test/files/run/t6546/B_2.scala @@ -0,0 +1,8 @@ +import scala.tools.partest.BytecodeTest + +object Test extends BytecodeTest { + def show: Unit = { + val node = loadClassNode("A_1") + assert(node.innerClasses.isEmpty, node.innerClasses) + } +} -- cgit v1.2.3 From e09a8a2b7f821be43703bd5bf3a064e171d8f66c Mon Sep 17 00:00:00 2001 From: Vlad Ureche Date: Mon, 2 Sep 2013 19:08:49 +0200 Subject: SI-4012 Mixin and specialization work well The bug was fixed along with SI-7638 in 504b5f3. --- test/files/pos/SI-4012-a.scala | 7 +++++++ test/files/pos/SI-4012-b.scala | 15 +++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 test/files/pos/SI-4012-a.scala create mode 100644 test/files/pos/SI-4012-b.scala (limited to 'test/files') diff --git a/test/files/pos/SI-4012-a.scala b/test/files/pos/SI-4012-a.scala new file mode 100644 index 0000000000..7fceeea3c3 --- /dev/null +++ b/test/files/pos/SI-4012-a.scala @@ -0,0 +1,7 @@ +trait C1[+A] { + def head: A = sys.error("") +} +trait C2[@specialized +A] extends C1[A] { + override def head: A = super.head +} +class C3 extends C2[Char] diff --git a/test/files/pos/SI-4012-b.scala b/test/files/pos/SI-4012-b.scala new file mode 100644 index 0000000000..6bc8592766 --- /dev/null +++ b/test/files/pos/SI-4012-b.scala @@ -0,0 +1,15 @@ +trait Super[@specialized(Int) A] { + def superb = 0 +} + +object Sub extends Super[Int] { + // it is expected that super[Super].superb crashes, since + // specialization does parent class rewiring, and the super + // of Sub becomes Super$mcII$sp and not Super. But I consider + // this normal behavior -- if you want, I can modify duplicatiors + // to make this work, but I consider it's best to keep this + // let the user know Super is not the superclass anymore. + // super[Super].superb - Vlad + super.superb // okay + override def superb: Int = super.superb // okay +} -- cgit v1.2.3 From 6045a05b833c930dfaf343215ac645f4f32f3e2a Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 6 Nov 2013 14:58:01 +0100 Subject: Fix completion after application with implicit arguments `List(1, 2, 3).map(f).` now works; before the tree had the type `(bf: CanBuildFrom[...]):...` and did not contribute completions from the result type. This commit checks if the tree has an implicit method type, and typechecks it as a qualifier. That is enough to get to `adaptToImplicitMethod` in the type checker, infer the implicit arguments, and compute the final result type accordingly. --- .../scala/tools/nsc/interactive/Global.scala | 9 +++++-- .../presentation/completion-implicit-chained.check | 29 ++++++++++++++++++++++ .../completion-implicit-chained/Test.scala | 3 +++ .../src/Completions.scala | 12 +++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 test/files/presentation/completion-implicit-chained.check create mode 100644 test/files/presentation/completion-implicit-chained/Test.scala create mode 100644 test/files/presentation/completion-implicit-chained/src/Completions.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala index 84670750d7..49f6cb2373 100644 --- a/src/compiler/scala/tools/nsc/interactive/Global.scala +++ b/src/compiler/scala/tools/nsc/interactive/Global.scala @@ -999,7 +999,13 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") val context = doLocateContext(pos) - if (tree.tpe == null) + val shouldTypeQualifier = tree.tpe match { + case null => true + case mt: MethodType => mt.isImplicit + case _ => false + } + + if (shouldTypeQualifier) // TODO: guard with try/catch to deal with ill-typed qualifiers. tree = analyzer.newTyper(context).typedQualifier(tree) @@ -1192,4 +1198,3 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") } object CancelException extends Exception - diff --git a/test/files/presentation/completion-implicit-chained.check b/test/files/presentation/completion-implicit-chained.check new file mode 100644 index 0000000000..6d30a61cf9 --- /dev/null +++ b/test/files/presentation/completion-implicit-chained.check @@ -0,0 +1,29 @@ +reload: Completions.scala + +askTypeCompletion at Completions.scala(11,16) +================================================================================ +[response] aksTypeCompletion at (11,16) +retrieved 24 members +[accessible: true] `method !=(x$1: Any)Boolean` +[accessible: true] `method !=(x$1: AnyRef)Boolean` +[accessible: true] `method ##()Int` +[accessible: true] `method ==(x$1: Any)Boolean` +[accessible: true] `method ==(x$1: AnyRef)Boolean` +[accessible: true] `method asInstanceOf[T0]=> T0` +[accessible: true] `method eq(x$1: AnyRef)Boolean` +[accessible: true] `method equals(x$1: Any)Boolean` +[accessible: true] `method hashCode()Int` +[accessible: true] `method isInstanceOf[T0]=> Boolean` +[accessible: true] `method map(x: Int => Int)(implicit a: DummyImplicit)test.O.type` +[accessible: true] `method ne(x$1: AnyRef)Boolean` +[accessible: true] `method notify()Unit` +[accessible: true] `method notifyAll()Unit` +[accessible: true] `method synchronized[T0](x$1: T0)T0` +[accessible: true] `method toString()String` +[accessible: true] `method wait()Unit` +[accessible: true] `method wait(x$1: Long)Unit` +[accessible: true] `method wait(x$1: Long, x$2: Int)Unit` +[accessible: true] `value prefix123Int` +[accessible: false] `method clone()Object` +[accessible: false] `method finalize()Unit` +================================================================================ diff --git a/test/files/presentation/completion-implicit-chained/Test.scala b/test/files/presentation/completion-implicit-chained/Test.scala new file mode 100644 index 0000000000..bec1131c4c --- /dev/null +++ b/test/files/presentation/completion-implicit-chained/Test.scala @@ -0,0 +1,3 @@ +import scala.tools.nsc.interactive.tests.InteractiveTest + +object Test extends InteractiveTest \ No newline at end of file diff --git a/test/files/presentation/completion-implicit-chained/src/Completions.scala b/test/files/presentation/completion-implicit-chained/src/Completions.scala new file mode 100644 index 0000000000..67922dfec0 --- /dev/null +++ b/test/files/presentation/completion-implicit-chained/src/Completions.scala @@ -0,0 +1,12 @@ +package test + +import scala.Predef.DummyImplicit // turn off other predef implicits for a cleaner .check file. + +object O { + def map(x: Int => Int)(implicit a: DummyImplicit): O.type = this + val prefix123 : Int = 0 +} + +class Foo { + O.map(x => x)./*!*/ // we want the presentation compiler to apply the implicit argument list. +} -- cgit v1.2.3