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

2.13.9 Good code error: x in variable x is never used. #12646

Closed
He-Pin opened this issue Sep 22, 2022 · 4 comments · Fixed by scala/scala#10154
Closed

2.13.9 Good code error: x in variable x is never used. #12646

He-Pin opened this issue Sep 22, 2022 · 4 comments · Fixed by scala/scala#10154

Comments

@He-Pin
Copy link
Contributor

He-Pin commented Sep 22, 2022

Reproduction steps

akka/akka#31615

Scala version: 2.13.9

Problem

[09-22 03:19:18.235] [error] /home/runner/work/akka/akka/akka-actor/src/main/scala/akka/actor/Actor.scala:331:15: parameter value _log_= in variable _log is never used
[09-22 03:19:18.235] [error]   private var _log: LoggingAdapter = _
[09-22 03:19:18.236] [error]        

I think the code is fine, but not ok when compile it with 2.13.9

image

Other issues:

  1. the variable is _log not _log_.
  2. it's local variable not parameter
@som-snytt
Copy link

Reproduction is trivial:

trait T {
  private var x: String = _

  def y: String = {
    if (x eq null) x = "hello, world"
    x
  }
}

and

➜  skalac -version
Scala compiler version 2.13.10-20220920-001308-98972e5 -- Copyright 2002-2022, LAMP/EPFL and Lightbend, Inc.

➜  skalac -d /tmp -Wunused -Vprint:typer t12646.scala
t12646.scala:3: warning: parameter value x_= in variable x is never used
  private var x: String = _
              ^
[[syntax trees at end of                     typer]] // t12646.scala
package <empty> {
  abstract trait T extends scala.AnyRef {
    def /*T*/$init$(): Unit = {
      ()
    };
    <accessor> private val x: String = _;
    <accessor> private def x_=(x$1: String): Unit;
    def y: String = {
      if (T.this.x.eq(null))
        T.this.x_=("hello, world")
      else
        ();
      T.this.x
    }
  }
}

1 warning

@jxnu-liguobin
Copy link
Member

jxnu-liguobin commented Sep 22, 2022

Is this as expected for the private accessor method?

It seems that this PR has changed this behavior.

@som-snytt
Copy link

The unused thing is the synthetic parameter to the setter. What?

@som-snytt
Copy link

Fix in linked PR. The strangeness has to do with fields in traits. I'm not sure why the parameter symbol is the setter (x_=) as shown in the confusing error message.

@SethTisue SethTisue added this to the 2.13.10 milestone Sep 23, 2022
eikek added a commit to SwissDataScienceCenter/renku-graph that referenced this issue Oct 6, 2022
Some source changes are required:

- Infering the type `Any` is now emitting a warning. All occurences
  have been annotated explicitely or the type parameters have been
  corrected.

- Working around issue scala/bug#12646 by
  moving a `var` from a `trait` into a `class`
eikek added a commit to SwissDataScienceCenter/renku-graph that referenced this issue Oct 6, 2022
Some source changes are required:

- Infering the type `Any` is now emitting a warning. All occurences
  have been annotated explicitely or the type parameters have been
  corrected.

- Working around issue scala/bug#12646 by
  moving a `var` from a `trait` into a `class`
eikek added a commit to SwissDataScienceCenter/renku-graph that referenced this issue Oct 7, 2022
Some source changes are required:

- Infering the type `Any` is now emitting a warning. All occurences
  have been annotated explicitely or the type parameters have been
  corrected.

- Working around issue scala/bug#12646 by
  moving a `var` from a `trait` into a `class`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants