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

Consider checking -Wnonunit-statement after macro expansion #22546

Open
kyri-petrou opened this issue Feb 7, 2025 · 1 comment
Open

Consider checking -Wnonunit-statement after macro expansion #22546

kyri-petrou opened this issue Feb 7, 2025 · 1 comment
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug

Comments

@kyri-petrou
Copy link

Compiler version

3.3.5, 3.6.3

Minimized code

//> using scala 3.6.3
//> using options -Wnonunit-statement, -Xfatal-warnings

object Main {
  def foo(): String = "foo"

  def code = scala.compiletime.codeOf {
    foo()
    foo()
  }
}

Output

Compiler warning / error:

unused value of type String
  foo()

Expectation

This code should not emit any warnings as the foo() statement is not discarded. This behaviour (checking for non-unit statements) is causing an issue for zio-test users that have this warning enabled; see zio/zio#9233 and zio/zio#9552.

@som-snytt
Copy link
Contributor

som-snytt commented Feb 7, 2025

-Wunused has the same open question. It wound up working like -Wmacros:default in Scala 2, where the expansion resolves references but does not introduce new definitions to be checked. Future work would be to offer more control, as
-Wmacros:before,after,either,both.

Open ticket about remaining compiletime behavior for that warning.
#21805

Oh, I created -Winlined as a placeholder or reminder, but nothing set in stone.

@Gedochao Gedochao 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 Feb 11, 2025
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