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

WarnUnsued false positive when using aliased imports from local value #17315

Closed
WojciechMazur opened this issue Apr 19, 2023 · 2 comments
Closed
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug

Comments

@WojciechMazur
Copy link
Contributor

Compiler version

3.3.0-RC4

Minimized code

//> using scala "3.3.0-RC4"
//> using option "-Wunused:all"

import java.io.DataOutputStream

val buffer: DataOutputStream = ???

import buffer.{write => put}

def usage() = {
  put(0: Byte)
}

Output

Compiling project (Scala 3.3.0-RC4, JVM)
[warn] ./test.scala:8:16
[warn] unused import
[warn] import buffer.{write => put, writeInt}
[warn]                

Expectation

Should not give warning

@WojciechMazur WojciechMazur added itype:bug area:linting Linting warnings enabled with -W or -Xlint labels Apr 19, 2023
@KacperFKorban
Copy link
Member

KacperFKorban commented Apr 20, 2023

I think that this is a very similar issue to transparent inline def. That is, in typer rename imports from vals are expanded to their fully qualified paths. e.g.

//> using scala "3.3.0-RC4"
//> using option "-Wunused:all"
//> using options "-Xprint:typer", "-Yplain-printer"

class baz {
  def write(x: Int) = ???
}

object foo extends baz

val bar: baz = ???

import bar.{write => put1}
import foo.{write => put2}

def usage() = {
  put1(0)
  put2(0)
}

The body of usage is (after typer):

Block(
  List(
    Apply(Select(Ident(bar), write), List(Literal(0)))
  ),
  Apply(Ident(put2), List(Literal(0)))
)

So this is again a choice between a possible false positive and a possible false negative. (Unless we think that adding attachments to trees just for unused is worth it)

@som-snytt
Copy link
Contributor

Duplicated by #18366

@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Projects
None yet
Development

No branches or pull requests

3 participants