Skip to content

Commit

Permalink
Remove eta-expansion of zero-arg method values
Browse files Browse the repository at this point in the history
Fixes scala/bug#7187

scala#5327 deprecates eta-expansion of zero-arg method values. This removes it in 2.13.
  • Loading branch information
eed3si9n committed Apr 8, 2018
1 parent ced7076 commit bc164c2
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 101 deletions.
8 changes: 4 additions & 4 deletions spec/06-expressions.md
Expand Up @@ -1400,16 +1400,16 @@ type $T$ by evaluating the expression to which $m$ is bound.
If the method takes only implicit parameters, implicit
arguments are passed following the rules [here](07-implicits.html#implicit-parameters).

###### Empty Application
Otherwise, if $e$ has method type $()T$, it is implicitly applied to the empty
argument list, yielding $e()$.

###### Eta Expansion
Otherwise, if the method is not a constructor,
and the expected type $\mathit{pt}$ is a function type
$(\mathit{Ts}') \Rightarrow T'$, [eta-expansion](#eta-expansion)
is performed on the expression $e$.

###### Empty Application
Otherwise, if $e$ has method type $()T$, it is implicitly applied to the empty
argument list, yielding $e()$.

### Overloading Resolution

If an identifier or selection $e$ references several members of a
Expand Down
15 changes: 5 additions & 10 deletions src/compiler/scala/tools/nsc/typechecker/Adaptations.scala
Expand Up @@ -70,16 +70,11 @@ trait Adaptations {

if (settings.noAdaptedArgs)
context.warning(t.pos, adaptWarningMessage("No automatic adaptation here: use explicit parentheses."))
else if (args.isEmpty) {
if (settings.future)
context.error(t.pos, adaptWarningMessage("Adaptation of argument list by inserting () has been removed.", 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")
}
} else if (settings.warnAdaptedArgs)
else if (args.isEmpty)
context.error(t.pos,
adaptWarningMessage(s"Adaptation of argument list by inserting () has been removed.",
showAdaptation = false))
else if (settings.warnAdaptedArgs)
context.warning(t.pos, adaptWarningMessage(
s"Adapting argument list by creating a ${args.size}-tuple: this may not be what you want.")
)
Expand Down
56 changes: 16 additions & 40 deletions test/files/neg/checksensible.check
@@ -1,21 +1,3 @@
checksensible.scala:45: warning: Adaptation of argument list by inserting () is deprecated: this is unlikely to be what you want.
signature: Any.==(x$1: Any): Boolean
given arguments: <none>
after adaptation: Any.==((): Unit)
() == ()
^
checksensible.scala:48: warning: Adaptation of argument list by inserting () is deprecated: this is unlikely to be what you want.
signature: Object.!=(x$1: Any): Boolean
given arguments: <none>
after adaptation: Object.!=((): Unit)
scala.runtime.BoxedUnit.UNIT != ()
^
checksensible.scala:49: warning: Adaptation of argument list by inserting () is deprecated: this is unlikely to be what you want.
signature: Any.!=(x$1: Any): Boolean
given arguments: <none>
after adaptation: Any.!=((): Unit)
(scala.runtime.BoxedUnit.UNIT: java.io.Serializable) != () // shouldn't warn
^
checksensible.scala:13: warning: comparing a fresh object using `eq' will always yield false
(new AnyRef) eq (new AnyRef)
^
Expand Down Expand Up @@ -62,59 +44,53 @@ checksensible.scala:44: warning: comparing values of types Unit and Boolean usin
() == true
^
checksensible.scala:45: warning: comparing values of types Unit and Unit using `==' will always yield true
() == ()
^
checksensible.scala:46: warning: comparing values of types Unit and Unit using `==' will always yield true
() == println
^
checksensible.scala:47: warning: comparing values of types Unit and scala.runtime.BoxedUnit using `==' will always yield true
checksensible.scala:46: warning: comparing values of types Unit and scala.runtime.BoxedUnit using `==' will always yield true
() == scala.runtime.BoxedUnit.UNIT // these should warn for always being true/false
^
checksensible.scala:48: warning: comparing values of types scala.runtime.BoxedUnit and Unit using `!=' will always yield false
scala.runtime.BoxedUnit.UNIT != ()
^
checksensible.scala:51: warning: comparing values of types Int and Unit using `!=' will always yield true
checksensible.scala:48: warning: comparing values of types Int and Unit using `!=' will always yield true
(1 != println)
^
checksensible.scala:52: warning: comparing values of types Int and Symbol using `!=' will always yield true
checksensible.scala:49: warning: comparing values of types Int and Symbol using `!=' will always yield true
(1 != 'sym)
^
checksensible.scala:58: warning: comparing a fresh object using `==' will always yield false
checksensible.scala:55: warning: comparing a fresh object using `==' will always yield false
((x: Int) => x + 1) == null
^
checksensible.scala:59: warning: comparing a fresh object using `==' will always yield false
checksensible.scala:56: warning: comparing a fresh object using `==' will always yield false
Bep == ((_: Int) + 1)
^
checksensible.scala:61: warning: comparing a fresh object using `==' will always yield false
checksensible.scala:58: warning: comparing a fresh object using `==' will always yield false
new Object == new Object
^
checksensible.scala:62: warning: comparing a fresh object using `==' will always yield false
checksensible.scala:59: warning: comparing a fresh object using `==' will always yield false
new Object == "abc"
^
checksensible.scala:63: warning: comparing a fresh object using `!=' will always yield true
checksensible.scala:60: warning: comparing a fresh object using `!=' will always yield true
new Exception() != new Exception()
^
checksensible.scala:66: warning: comparing values of types Int and Null using `==' will always yield false
checksensible.scala:63: warning: comparing values of types Int and Null using `==' will always yield false
if (foo.length == null) "plante" else "plante pas"
^
checksensible.scala:71: warning: comparing values of types Bip and Bop using `==' will always yield false
checksensible.scala:68: warning: comparing values of types Bip and Bop using `==' will always yield false
(x1 == x2)
^
checksensible.scala:81: warning: comparing values of types EqEqRefTest.this.C3 and EqEqRefTest.this.Z1 using `==' will always yield false
checksensible.scala:78: warning: comparing values of types EqEqRefTest.this.C3 and EqEqRefTest.this.Z1 using `==' will always yield false
c3 == z1
^
checksensible.scala:82: warning: comparing values of types EqEqRefTest.this.Z1 and EqEqRefTest.this.C3 using `==' will always yield false
checksensible.scala:79: warning: comparing values of types EqEqRefTest.this.Z1 and EqEqRefTest.this.C3 using `==' will always yield false
z1 == c3
^
checksensible.scala:83: warning: comparing values of types EqEqRefTest.this.Z1 and EqEqRefTest.this.C3 using `!=' will always yield true
checksensible.scala:80: warning: comparing values of types EqEqRefTest.this.Z1 and EqEqRefTest.this.C3 using `!=' will always yield true
z1 != c3
^
checksensible.scala:84: warning: comparing values of types EqEqRefTest.this.C3 and String using `!=' will always yield true
checksensible.scala:81: warning: comparing values of types EqEqRefTest.this.C3 and String using `!=' will always yield true
c3 != "abc"
^
checksensible.scala:95: warning: comparing values of types Unit and Int using `!=' will always yield true
checksensible.scala:92: warning: comparing values of types Unit and Int using `!=' will always yield true
while ((c = in.read) != -1)
^
error: No warnings can be incurred under -Xfatal-warnings.
36 warnings found
31 warnings found
one error found
3 changes: 0 additions & 3 deletions test/files/neg/checksensible.scala
Expand Up @@ -42,11 +42,8 @@ class EqEqValTest {

1 != true
() == true
() == ()
() == println
() == scala.runtime.BoxedUnit.UNIT // these should warn for always being true/false
scala.runtime.BoxedUnit.UNIT != ()
(scala.runtime.BoxedUnit.UNIT: java.io.Serializable) != () // shouldn't warn

(1 != println)
(1 != 'sym)
Expand Down
17 changes: 6 additions & 11 deletions test/files/neg/t4851.check
@@ -1,13 +1,11 @@
S.scala:2: warning: Adaptation of argument list by inserting () is deprecated: leaky (Object-receiving) target makes this especially dangerous.
S.scala:2: error: Adaptation of argument list by inserting () has been removed.
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: error: Adaptation of argument list by inserting () has been removed.
signature: J(x: Any): J
given arguments: <none>
after adaptation: new J((): Unit)
val x2 = new J()
^
S.scala:4: warning: Adapting argument list by creating a 5-tuple: this may not be what you want.
Expand All @@ -28,16 +26,14 @@ S.scala:7: warning: Adapting argument list by creating a 3-tuple: this may not b
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: error: Adaptation of argument list by inserting () has been removed.
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: error: Adaptation of argument list by inserting () has been removed.
signature: J2(x: T): J2[T]
given arguments: <none>
after adaptation: new J2((): Unit)
val z2 = new J2()
^
S.scala:14: warning: Adapting argument list by creating a 3-tuple: this may not be what you want.
Expand All @@ -46,6 +42,5 @@ S.scala:14: warning: Adapting argument list by creating a 3-tuple: this may not
after adaptation: Test.anyId((1, 2, 3): (Int, Int, Int))
val w1 = anyId(1, 2 ,3)
^
error: No warnings can be incurred under -Xfatal-warnings.
8 warnings found
one error found
four warnings found
four errors found
21 changes: 0 additions & 21 deletions test/files/neg/t8035-deprecated.check

This file was deleted.

1 change: 0 additions & 1 deletion test/files/neg/t8035-deprecated.flags

This file was deleted.

10 changes: 0 additions & 10 deletions test/files/neg/t8035-deprecated.scala

This file was deleted.

1 change: 0 additions & 1 deletion test/files/neg/t8035-removed.flags

This file was deleted.

0 comments on commit bc164c2

Please sign in to comment.