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

private val is never used - incorrectly issued when there is no val #9518

Closed
scabug opened this issue Oct 15, 2015 · 4 comments
Closed

private val is never used - incorrectly issued when there is no val #9518

scabug opened this issue Oct 15, 2015 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Oct 15, 2015

I have lots of unit test code with lines like this:

@Test def bar() {
    ...
    val Seq(_, _) = foo() // produces warning unused
    ...
}

When I have warn-unused turned on, I get a warning on this:

private val in method bar is never used.

But notice, there is no val here. I've used the underscore here.

I don't have a workaround to suppress this warning other than rewriting as

@Test def bar () {
    foo() match { case Seq(_,_) => /* ok */ }
}

Having to permute the source code into a match-case just to suppress this spurious warning is painful, and there is a loss of code symmetry I don't like, as lots of other very similar tests look like:

@Test def bar2() {
    val Seq(a, _) = foo2()
    assertEquals("a", a)
}

This does not produce the spurious warning.

@scabug
Copy link
Author

scabug commented Oct 15, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9518?orig=1
Reporter: Michael Beckerle (mbeckerle.dfdl)
Affected Versions: 2.11.7

@scabug
Copy link
Author

scabug commented Oct 15, 2015

Michael Beckerle (mbeckerle.dfdl) said:
Note: same problem occurs if you do this:

case class Foo(x: String, y: Int)

@Test def testFoo {
...
   val Foo("a", 5) = bar() // spurious warning about unused val
...
}

Again notice, there is no val to be unused here.

@scabug
Copy link
Author

scabug commented Oct 15, 2015

@som-snytt said:
Maybe sufficient to avoid warning about a synthetic.

@scabug
Copy link
Author

scabug commented Sep 14, 2016

@som-snytt said:
scala/scala#5402

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

No branches or pull requests

2 participants