Skip to content

Commit

Permalink
Remove adaptation of 0-arg methods under -Xsource:3.0
Browse files Browse the repository at this point in the history
Get thee to a nullary, go. Farewell -Xfuture.

Ref scala/bug#8035
  • Loading branch information
eed3si9n authored and som-snytt committed Jul 28, 2018
1 parent d0eb431 commit 3900f7d
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala
Expand Up @@ -629,7 +629,7 @@ abstract class BTypes {
// synchronization required to ensure the apply is finished
// which populates info. ClassBType doesnt escape apart from via the map
// and the object mutex is locked prior to insertion. See apply
this.synchronized()
this.synchronized {}
assert(_info != null, s"ClassBType.info not yet assigned: $this")
_info
}
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
Expand Up @@ -98,6 +98,8 @@ trait ScalaSettings extends AbsScalaSettings
def isScala213: Boolean = source.value >= version213
private[this] val version214 = ScalaVersion("2.14.0")
def isScala214: Boolean = source.value >= version214
private[this] val version3_0 = ScalaVersion("3.0.0")
def isScala3: Boolean = source.value >= version3_0

/**
* -X "Advanced" settings
Expand Down
15 changes: 8 additions & 7 deletions src/compiler/scala/tools/nsc/typechecker/Adaptations.scala
Expand Up @@ -67,21 +67,22 @@ trait Adaptations {
}

if (args.isEmpty) {
if (settings.future)
context.error(t.pos, adaptWarningMessage("Adaptation of argument list by inserting () has been removed.", showAdaptation = false))
def msg(what: String): String = s"adaptation of an empty argument list by appending () is $what"
if (settings.isScala3)
context.error(t.pos, adaptWarningMessage(msg("unsupported"), showAdaptation = false))
else {
val msg = "Adaptation of argument list by inserting () is deprecated: " + (
if (isLeakyTarget) "leaky (Object-receiving) target makes this especially dangerous."
else "this is unlikely to be what you want.")
context.deprecationWarning(t.pos, t.symbol, adaptWarningMessage(msg), "2.11.0")
context.deprecationWarning(t.pos, t.symbol, adaptWarningMessage(
msg("deprecated") + ": " + (
if (isLeakyTarget) "leaky (Object-receiving) target makes this especially dangerous"
else "this is unlikely to be what you want")), "2.11.0")
}
} else if (settings.warnAdaptedArgs)
context.warning(t.pos, adaptWarningMessage(
s"adapted the argument list to the expected ${args.size}-tuple: add additional parens instead")
)

// return `true` if the adaptation should be kept
!(args.isEmpty && settings.future)
!(args.isEmpty && settings.isScala3)
}
}
}
1 change: 0 additions & 1 deletion test/files/jvm/future-spec.check
@@ -1 +0,0 @@
warning: there was one deprecation warning (since 2.11.0); re-run with -deprecation for details
5 changes: 4 additions & 1 deletion test/files/jvm/future-spec/FutureTests.scala
@@ -1,3 +1,5 @@
/* scalac: -Xsource:3.0 */

import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.duration.Duration.Inf
Expand Down Expand Up @@ -39,7 +41,8 @@ class FutureTests extends MinimalScalaTest {
val ms = new concurrent.TrieMap[Throwable, Unit]
implicit val ec = scala.concurrent.ExecutionContext.fromExecutor(new java.util.concurrent.ForkJoinPool(), {
t =>
ms += (t -> ())
val u = ()
ms += (t -> u)
})

class ThrowableTest(m: String) extends Throwable(m)
Expand Down
12 changes: 12 additions & 0 deletions test/files/neg/checksensible.check
@@ -1,17 +1,29 @@
<<<<<<< b357b3a7376da5eacdd23ed0ca14ae107028618e
#partest java8
checksensible.scala:47: warning: Adaptation of argument list by inserting () is deprecated: this is unlikely to be what you want.
=======
checksensible.scala:45: warning: adaptation of an empty argument list by appending () is deprecated: this is unlikely to be what you want
>>>>>>> Remove adaptation of 0-arg methods under -Xsource:3.0
signature: Any.==(x$1: Any): Boolean
given arguments: <none>
after adaptation: Any.==((): Unit)
() == ()
^
<<<<<<< b357b3a7376da5eacdd23ed0ca14ae107028618e
checksensible.scala:50: warning: Adaptation of argument list by inserting () is deprecated: this is unlikely to be what you want.
=======
checksensible.scala:48: warning: adaptation of an empty argument list by appending () is deprecated: this is unlikely to be what you want
>>>>>>> Remove adaptation of 0-arg methods under -Xsource:3.0
signature: Object.!=(x$1: Any): Boolean
given arguments: <none>
after adaptation: Object.!=((): Unit)
scala.runtime.BoxedUnit.UNIT != ()
^
<<<<<<< b357b3a7376da5eacdd23ed0ca14ae107028618e
checksensible.scala:51: warning: Adaptation of argument list by inserting () is deprecated: this is unlikely to be what you want.
=======
checksensible.scala:49: warning: adaptation of an empty argument list by appending () is deprecated: this is unlikely to be what you want
>>>>>>> Remove adaptation of 0-arg methods under -Xsource:3.0
signature: Any.!=(x$1: Any): Boolean
given arguments: <none>
after adaptation: Any.!=((): Unit)
Expand Down
8 changes: 4 additions & 4 deletions test/files/neg/t4851.check
@@ -1,10 +1,10 @@
S.scala:2: warning: Adaptation of argument list by inserting () is deprecated: leaky (Object-receiving) target makes this especially dangerous.
S.scala:2: warning: adaptation of an empty argument list by appending () is deprecated: leaky (Object-receiving) target makes this especially dangerous
signature: J(x: Any): J
given arguments: <none>
after adaptation: new J((): Unit)
val x1 = new J
^
S.scala:3: warning: Adaptation of argument list by inserting () is deprecated: leaky (Object-receiving) target makes this especially dangerous.
S.scala:3: warning: adaptation of an empty argument list by appending () is deprecated: leaky (Object-receiving) target makes this especially dangerous
signature: J(x: Any): J
given arguments: <none>
after adaptation: new J((): Unit)
Expand All @@ -28,13 +28,13 @@ S.scala:7: warning: adapted the argument list to the expected 3-tuple: add addit
after adaptation: new Some((1, 2, 3): (Int, Int, Int))
val y2 = new Some(1, 2, 3)
^
S.scala:9: warning: Adaptation of argument list by inserting () is deprecated: this is unlikely to be what you want.
S.scala:9: warning: adaptation of an empty argument list by appending () is deprecated: this is unlikely to be what you want
signature: J2(x: T): J2[T]
given arguments: <none>
after adaptation: new J2((): Unit)
val z1 = new J2
^
S.scala:10: warning: Adaptation of argument list by inserting () is deprecated: this is unlikely to be what you want.
S.scala:10: warning: adaptation of an empty argument list by appending () is deprecated: this is unlikely to be what you want
signature: J2(x: T): J2[T]
given arguments: <none>
after adaptation: new J2((): Unit)
Expand Down
12 changes: 12 additions & 0 deletions test/files/neg/t8035-deprecated.check
@@ -1,16 +1,28 @@
<<<<<<< b357b3a7376da5eacdd23ed0ca14ae107028618e
t8035-deprecated.scala:4: warning: Adaptation of argument list by inserting () is deprecated: this is unlikely to be what you want.
=======
t8035-deprecated.scala:2: warning: adaptation of an empty argument list by appending () is deprecated: this is unlikely to be what you want
>>>>>>> Remove adaptation of 0-arg methods under -Xsource:3.0
signature: SetOps.apply(elem: A): Boolean
given arguments: <none>
after adaptation: SetOps((): Unit)
List(1,2,3).toSet()
^
<<<<<<< b357b3a7376da5eacdd23ed0ca14ae107028618e
t8035-deprecated.scala:7: warning: Adaptation of argument list by inserting () is deprecated: this is unlikely to be what you want.
=======
t8035-deprecated.scala:5: warning: adaptation of an empty argument list by appending () is deprecated: this is unlikely to be what you want
>>>>>>> Remove adaptation of 0-arg methods under -Xsource:3.0
signature: A(x: T): Foo.A[T]
given arguments: <none>
after adaptation: new A((): Unit)
new A
^
<<<<<<< b357b3a7376da5eacdd23ed0ca14ae107028618e
t8035-deprecated.scala:11: warning: Adaptation of argument list by inserting () is deprecated: leaky (Object-receiving) target makes this especially dangerous.
=======
t8035-deprecated.scala:9: warning: adaptation of an empty argument list by appending () is deprecated: leaky (Object-receiving) target makes this especially dangerous
>>>>>>> Remove adaptation of 0-arg methods under -Xsource:3.0
signature: Format.format(x$1: Any): String
given arguments: <none>
after adaptation: Format.format((): Unit)
Expand Down
12 changes: 12 additions & 0 deletions test/files/neg/t8035-removed.check
@@ -1,14 +1,26 @@
<<<<<<< b357b3a7376da5eacdd23ed0ca14ae107028618e
t8035-removed.scala:4: error: Adaptation of argument list by inserting () has been removed.
=======
t8035-removed.scala:4: error: adaptation of an empty argument list by appending () is unsupported
>>>>>>> Remove adaptation of 0-arg methods under -Xsource:3.0
signature: SetOps.apply(elem: A): Boolean
given arguments: <none>
List(1,2,3).toSet()
^
<<<<<<< b357b3a7376da5eacdd23ed0ca14ae107028618e
t8035-removed.scala:7: error: Adaptation of argument list by inserting () has been removed.
=======
t8035-removed.scala:7: error: adaptation of an empty argument list by appending () is unsupported
>>>>>>> Remove adaptation of 0-arg methods under -Xsource:3.0
signature: A(x: T): Foo.A[T]
given arguments: <none>
new A
^
<<<<<<< b357b3a7376da5eacdd23ed0ca14ae107028618e
t8035-removed.scala:11: error: Adaptation of argument list by inserting () has been removed.
=======
t8035-removed.scala:11: error: adaptation of an empty argument list by appending () is unsupported
>>>>>>> Remove adaptation of 0-arg methods under -Xsource:3.0
signature: Format.format(x$1: Any): String
given arguments: <none>
sdf.format()
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/t8035-removed.scala
@@ -1,4 +1,4 @@
// scalac: -Xfuture
// scalac:-Xsource:3.0
//
object Foo {
List(1,2,3).toSet()
Expand Down
4 changes: 3 additions & 1 deletion test/files/pos/t5413.scala
@@ -1,9 +1,11 @@
/* scalac: -Xsource:3.0 */

object Fail {
def nom (guard : => Boolean) (something : => Unit): Unit = { }
def main(args: Array[String]): Unit = {
nom {
val i = 0
(i != 3)
}()
}(())
}
}
2 changes: 1 addition & 1 deletion test/files/run/macro-range.flags
@@ -1 +1 @@
-language:experimental.macros
-language:experimental.macros -Xsource:3.0
2 changes: 1 addition & 1 deletion test/files/run/macro-range/Common_1.scala
Expand Up @@ -40,7 +40,7 @@ abstract class Utils {
}
def makeWhile(lname: TermName, cond: Tree, body: Tree): Tree = {
val continu = Apply(Ident(lname), Nil)
val rhs = If(cond, Block(List(body), continu), Literal(Constant()))
val rhs = If(cond, Block(List(body), continu), Literal(Constant(())))
LabelDef(lname, Nil, rhs)
}
def makeBinop(left: Tree, op: String, right: Tree): Tree =
Expand Down
1 change: 0 additions & 1 deletion test/files/run/t576.check
@@ -1,4 +1,3 @@
warning: there was one deprecation warning (since 2.11.0); re-run with -deprecation for details
1
2
3
Expand Down
7 changes: 6 additions & 1 deletion test/files/run/t576.scala
@@ -1,3 +1,5 @@
/* -Xsource:3.0 */

import scala.language.reflectiveCalls

class A {
Expand Down Expand Up @@ -35,7 +37,10 @@ object Test {

assert(x1 == x1)
assert(x1 != x2)
assert(x1 != ())

// This is a workaround for x1 != (())
val unit = ()
assert(x1 != unit)
assert(x2 != x1)

assert(x3 == x3)
Expand Down
17 changes: 8 additions & 9 deletions test/files/run/t6863.check
@@ -1,13 +1,12 @@
t6863.scala:38: warning: comparing values of types Unit and Unit using `==' will always yield true
assert({ () => x}.apply == ())
t6863.scala:43: warning: comparing values of types Unit and Unit using `==' will always yield true
assert({ () => x}.apply == u)
^
t6863.scala:42: warning: comparing values of types Unit and Unit using `==' will always yield true
assert({ () => x}.apply == ())
t6863.scala:47: warning: comparing values of types Unit and Unit using `==' will always yield true
assert({ () => x}.apply == u)
^
t6863.scala:46: warning: comparing values of types Unit and Unit using `==' will always yield true
assert({ () => x}.apply == ())
t6863.scala:51: warning: comparing values of types Unit and Unit using `==' will always yield true
assert({ () => x}.apply == u)
^
t6863.scala:59: warning: comparing values of types Unit and Unit using `==' will always yield true
assert({ () => x }.apply == ())
t6863.scala:64: warning: comparing values of types Unit and Unit using `==' will always yield true
assert({ () => x }.apply == u)
^
warning: there were four deprecation warnings (since 2.11.0); re-run with -deprecation for details
13 changes: 9 additions & 4 deletions test/files/run/t6863.scala
@@ -1,5 +1,10 @@
/* scalac: -Xsource:3.0 */

/** Make sure that when a variable is captured its initialization expression is handled properly */
object Test {
// This is a workaround for x == (())
val u = ()

def lazyVal() = {
// internally lazy vals become vars which are initialized with "_", so they need to be tested just like vars do
lazy val x = "42"
Expand Down Expand Up @@ -35,15 +40,15 @@ object Test {
def assign() = {
var y = 1
var x = y = 42
assert({ () => x}.apply == ())
assert({ () => x}.apply == u)
}
def valDef() = {
var x = {val y = 42}
assert({ () => x}.apply == ())
assert({ () => x}.apply == u)
}
def `return`(): String = {
var x = if (true) return "42" else ()
assert({ () => x}.apply == ())
assert({ () => x}.apply == u)
"42"
}
def tryFinally() = {
Expand All @@ -56,7 +61,7 @@ object Test {
}
def `if`() = {
var x = if (true) ()
assert({ () => x }.apply == ())
assert({ () => x }.apply == u)
}
def ifElse() = {
var x = if(true) "42" else "43"
Expand Down
1 change: 0 additions & 1 deletion test/files/run/t6935.check
@@ -1 +0,0 @@
warning: there was one deprecation warning (since 2.11.0); re-run with -deprecation for details
8 changes: 6 additions & 2 deletions test/files/run/t6935.scala
@@ -1,3 +1,5 @@
/* scalac: -Xsource:3.0 */

object Test {

def main(args: Array[String]): Unit = {
Expand All @@ -8,7 +10,9 @@ object Test {
out.close()
val buf = bytes.toByteArray
val in = new ObjectInputStream(new ByteArrayInputStream(buf))
val unit = in.readObject()
assert(unit == ())
val actual = in.readObject()
// This is a workaround for actual == (())
val unit = ()
assert(actual == unit)
}
}
Expand Up @@ -72,7 +72,7 @@ class StringContextTest {

// verifying that the standard interpolators can be supplanted
@Test def antiHijack_?() = {
object AllYourStringsAreBelongToMe { case class StringContext(args: Any*) { def s(args: Any) = "!!!!" } }
object AllYourStringsAreBelongToMe { case class StringContext(args: Any*) { def s(args: Any*) = "!!!!" } }
import AllYourStringsAreBelongToMe._
//assertEquals("????", s"????")
assertEquals("!!!!", s"????") // OK to hijack core interpolator ids
Expand Down

0 comments on commit 3900f7d

Please sign in to comment.