Skip to content

False positive unused import of inline given needed by derives #23201

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

Open
aartigao opened this issue May 20, 2025 · 1 comment
Open

False positive unused import of inline given needed by derives #23201

aartigao opened this issue May 20, 2025 · 1 comment
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug

Comments

@aartigao
Copy link

I've checked other opened issues and it doesn't seem there's one like this (if that's the case, sorry and please close this).

Also I'm not sure since when the issue appears because we have excluded the unused import warnings in our projects. The minimizer, though, I tried with 3.7.1-RC1 and 3.nightly.

Compiler version

3.nightly

Minimized code

//> using scala 3.nightly
//> using dep com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-core:2.36.0
//> using dep io.github.kitlangton::neotype-jsoniter:0.3.24
//> using options -Wunused:imports

import com.github.plokhotnyuk.jsoniter_scala.core.*
import com.github.plokhotnyuk.jsoniter_scala.macros.*
import neotype.*
import neotype.interop.jsoniter.given

type Bar = Bar.Type
object Bar extends Newtype[Long]

case class Foo(bar: Bar, bars: List[Bar]) derives ConfiguredJsonValueCodec

object JsonExample:

  def main(args: Array[String]): Unit =
    val foo = Foo(Bar(42), List(Bar(1), Bar(2)))
    val jsonString = writeToString(foo)
    println(s"Serialized JSON: $jsonString")

    val parsedFoo = readFromString[Foo](jsonString)
    println(s"Deserialized object: $parsedFoo")

Output

[warn] ./issue.sc:9:33
[warn] unused import
[warn] import neotype.interop.jsoniter.given
[warn]   

Expectation

No warn is emitted as this import is needed by Jsoniter derives.

The import, when removed as suggested by the compiler, makes the compilation fail:

[error] ./issue.sc:14:51
[error] No implicit 'com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec[_ >: scala.Nothing <: scala.Any]' defined for 'issue$_.this.Bar.Type'.
[error] case class Foo(bar: Bar, bars: List[Bar]) derives ConfiguredJsonValueCodec
[error]      
@aartigao aartigao added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 20, 2025
@som-snytt
Copy link
Contributor

The imported symbol is inline given, but recursing into Inlined was reverted and still needs to be addressed.

This is just to show the inlined newtypeCodec under -Yplain-printer.

Inlined(Thicket(List()), List(),
  Inlined(Ident(JsonCodecMaker$),
    List(),
    Block(
      List(
        Apply(
          Select(
            Inlined(Thicket(List()),
              List(), Ident(x)),
          addOne),
        List(
          Inlined(Thicket(List()),
            List(),
            Inlined(
              Ident(JsonCodecMaker$),
              List(),
              Apply(
                Select(
                  Inlined(
                    Thicket(List()),
                    List(),
                    Inlined(
                      Apply(
                        TypeApply(
                          Ident(
                            newtypeCodec
                            ),
                        List(TypeTree(),
                          TypeTree())),
                        List(
                        NamedArg(
                          newType,

@som-snytt som-snytt changed the title False positive unused import needed by derives False positive unused import of inline given needed by derives May 20, 2025
@som-snytt som-snytt 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 May 20, 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

2 participants