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

Unused local from HasNoScope macro #9690

Open
amumurst opened this issue Mar 12, 2025 · 5 comments
Open

Unused local from HasNoScope macro #9690

amumurst opened this issue Mar 12, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@amumurst
Copy link

amumurst commented Mar 12, 2025

The HasNoScope type added in #9604 triggered some unused local warnings when I tried to update zio-http to 3.1.0

I managed to minimize the issue from originally being a part of a for-comprehension over ZIO using the zio-http server https://github.com/zio/zio-http/pull/3276/files#diff-15253ca7746d023f47e1c8c4c34e48cbfcd752426fac4b0f9536279e9a7c4b7bR37 down to the value being a part of any local scope (not only map/flatMap)

main.sc

//> using dep "dev.zio::zio-http:3.1.0"
//> using options "-Wunused:locals" "-Xfatal-warnings"

import zio.*
val x: HasNoScope[Any] = HasNoScope.hasNoScope[Any] //Works
val z: HasNoScope[Any] = { HasNoScope.hasNoScope[Any] } //Warning

output

[error] ./main.sc:6:49
[error] unused local definition
[error] val z: HasNoScope[Any] = { HasNoScope.hasNoScope[Any] } //Unused
[error]         
@hearnadam hearnadam added the bug Something isn't working label Mar 14, 2025
@hearnadam
Copy link
Collaborator

JFYI @987Nabil

@987Nabil
Copy link
Contributor

I'll take a look

@987Nabil
Copy link
Contributor

I tried inlining the code of the macro and using the return value of the macro

//> using dep "dev.zio::zio-http:3.1.0"
//> using options "-Wunused:locals" "-Xfatal-warnings"

import zio.*
val x: HasNoScope[Any] = HasNoScope.hasNoScope[Any] //Works
val z: HasNoScope[Any] = {
  val x = HasNoScope.hasNoScope[Any]
  println(x)
  x
} //Warning
val x1: HasNoScope[Any] = HasNoScope.instance.asInstanceOf[HasNoScope[Any]] //Works
val z1: HasNoScope[Any] = {
  val x = HasNoScope.instance.asInstanceOf[HasNoScope[Any]]
  println(x)
  x
} //Warning

@main def test = println("Hello World")

It seems to me like a Scala bug. Any other oppinion?

@amumurst
Copy link
Author

z1 does not give a warning for me

@987Nabil
Copy link
Contributor

@amumurst exactly. It is only the expended macro. This leads me to the assumption, that this is a bug in the compiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants