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

-Wunused:locals gives false positives for some calls to transparent inline functions #17753

Open
matil019 opened this issue Jun 2, 2023 · 5 comments
Assignees
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug

Comments

@matil019
Copy link

matil019 commented Jun 2, 2023

Compiler version

3.3.0

Minimized code

//> using option -Wunused:locals
//> using scala 3.3.0

class PartiallyApplied[A] {
  transparent inline def func[B](): Nothing = ???
}

def call[A] = new PartiallyApplied[A]

def good = call[Int].func[String]()
def bad = { call[Int].func[String]() }

Output

-- Warning: /home/...snip.../Foo.scala:11:34 -------------------
11 |def bad = { call[Int].func[String]() }
   |                                  ^
   |                                  unused local definition
1 warning found

Expectation

No warnings are issued.

Other

This affects Monocle's macros such as GenLens.

I'm not certain whether or not my example can be minimized further. Interestingly, calling a transparent inline function directly doesn't trigger any warnings.

//> using option -Wunused:locals
//> using scala 3.3.0

transparent inline def func2[A]() = ???

def good2a = func2[Int]()
def good2b = { func2[Int]() }
@matil019 matil019 added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 2, 2023
@jchyb jchyb added area:linting Linting warnings enabled with -W or -Xlint and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 2, 2023
@ritschwumm
Copy link

looks like my own lens macro suffers the same issue, and it's a bit annoying to switch off warnings where ever i construct a lens. is there a workaround i can try maybe?

@szymon-rd szymon-rd self-assigned this Aug 28, 2023
@ritschwumm
Copy link

any news on this? the problem still seems to persist in 3.4.0-RC1

@som-snytt
Copy link
Contributor

It has to do with the tree representation Inlined; it must learn to ignore the bindings that are warning.

@jtjeferreira
Copy link
Contributor

looks like my own lens macro suffers the same issue

Also faced this issue in optics-dev/Monocle#1484

@som-snytt
Copy link
Contributor

som-snytt commented Dec 12, 2024

@jtjeferreira thanks I just returned to my PR to fix unused bugs, so I'll try out your example. Sorry I missed last release cycle. Assigned myself as a reminder.

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

6 participants