Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected compilation warnings: Auto-application to () is deprecated. #2297

Open
LuciferYang opened this issue Oct 18, 2023 · 5 comments
Open

Comments

@LuciferYang
Copy link

LuciferYang commented Oct 18, 2023

The test code is as follows and the test file named IsEmptySuite.scala

import org.scalatest.funsuite.AnyFunSuite // scalastyle:ignore funsuite
class IsEmptySuite extends AnyFunSuite { // scalastyle:ignore funsuite
  class Foo {
    def isEmpty(): Boolean = true
    def isTrue(x: Boolean): Boolean = x
  }
  test("test Foo#isEmpty") {
    val foo = new Foo
    Predef.assert(foo.isEmpty()) // no compilation warnings.
    assert(foo.isEmpty() === true) // no compilation warnings.
    assert(foo.isTrue(foo.isEmpty())) // no compilation warnings.
    assert(foo.isEmpty()) // an unexpected compilation warning.
  }
}

Then we I compile the code with Scala 2.13+

bin/scalac -deprecation  -classpath scalatest-funsuite_2.13-3.2.17.jar:scalatest-core_2.13-3.2.17.jar:scalactic_2.13-3.2.17.jar:scalatest-compatible-3.2.17.jar IsEmptySuite.scala

There will be compilation warning as follows:

IsEmptySuite.scala:12: warning: Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method isEmpty,
or remove the empty argument list from its definition (Java-defined methods are exempt).
In Scala 3, an unapplied method like this will be eta-expanded into a function.
    assert(foo.isEmpty()) // an unexpected compilation warning.
          ^
1 warning

I want to know why this compile warning occurs on the last assertion line but not on the others. Other than renaming isEmpty() to isEmpty, are there any other methods to eliminate this compile warning?

@LuciferYang
Copy link
Author

friendly ping @cheeseng , I'm not sure whether this question should be directed to you and the scalatest community. I would be very happy if I could receive your help. Thanks ~

@cheeseng
Copy link
Contributor

@LuciferYang I think that's probably coming from code generated by our Scala 2 macro, I'll take a look at this today.

@LuciferYang
Copy link
Author

@LuciferYang I think that's probably coming from code generated by our Scala 2 macro, I'll take a look at this today.

Thanks very much for your help ~

cheeseng added a commit to cheeseng/scalatest that referenced this issue Oct 19, 2023
@cheeseng
Copy link
Contributor

@LuciferYang Fyi I submitted the following PR for this:

#2298

srowen pushed a commit to apache/spark that referenced this issue Oct 22, 2023
…IB][K8S][YARN][SHELL][PYTHON][R][AVRO][UI][EXAMPLES] Fix the compilation warning "Auto-application to `()` is deprecated" and turn it into a compilation error

### What changes were proposed in this pull request?
This PR mainly does two things:
1. Clean up all compilation warnings related to "Auto-application to () is deprecated".
2. Change the compilation options to convert this compilation warning into a compilation error.

Additionally, due to an issue with scalatest(scalatest/scalatest#2297), there are some false positives. Therefore, this PR has added the corresponding rules to suppress them, and left the corresponding TODO(SPARK-45615). We can clean up these rules after scalatest fixes this issue(scalatest/scalatest#2298).

### Why are the changes needed?
1. Clean up the deprecated usage methods.
2. As this compilation warning will become a compilation error in Scala 3, to ensure it does not occur again, this PR also converts it into a compilation error in Scala 2.13.

For example, for the following code:

```scala
class Foo {
  def isEmpty(): Boolean = true
}
val foo = new Foo
val ret = foo.isEmpty
```

In Scala 2.13:

```
Welcome to Scala 2.13.12 (OpenJDK 64-Bit Server VM, Java 17.0.8).
Type in expressions for evaluation. Or try :help.

scala> class Foo {
     |   def isEmpty(): Boolean = true
     | }
class Foo

scala> val foo = new Foo
     |
val foo: Foo = Foo7e15f4d4

scala> val ret = foo.isEmpty
                     ^
       warning: Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method isEmpty,
       or remove the empty argument list from its definition (Java-defined methods are exempt).
       In Scala 3, an unapplied method like this will be eta-expanded into a function. [quickfixable]
val ret: Boolean = true
```

In Scala 3:

```
Welcome to Scala 3.3.1 (17.0.8, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> class Foo {
     |   def isEmpty(): Boolean = true
     | }
// defined class Foo

scala> val foo = new Foo
val foo: Foo = Foo150d6eaf

scala> val ret = foo.isEmpty
-- [E100] Syntax Error: --------------------------------------------------------
1 |val ret = foo.isEmpty
  |          ^^^^^^^^^^^
  |          method isEmpty in class Foo must be called with () argument
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | Previously an empty argument list () was implicitly inserted when calling a nullary method without arguments. E.g.
  |
  | def next(): T = ...
  |         |next     // is expanded to next()
  |
  | In Dotty, this idiom is an error. The application syntax has to follow exactly the parameter syntax.
  | Excluded from this rule are methods that are defined in Java or that override methods defined in Java.
   -----------------------------------------------------------------------------
1 error found

```

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Pass GitHub Actions

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #43472 from LuciferYang/SPARK-45610.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Sean Owen <srowen@gmail.com>
dongjoon-hyun pushed a commit to apache/spark that referenced this issue Feb 20, 2024
…ecated" compile suppression rules

### What changes were proposed in this pull request?
This pr aims to remove undated `Auto-application to () is deprecated` compile suppression rules added by SPARK-45610 because SPARK-47016 already upgrade `scalatest` to 3.2.18 and the issue has been fixed.

### Why are the changes needed?
master has already upgraded `scalatest` to 3.2.18, the issue described in scalatest/scalatest#2297 has been resolved.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Pass GitHub Actions

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #45179 from LuciferYang/SPARK-45615.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
@som-snytt
Copy link

@cheeseng this issue was not auto-closed when the PR was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants