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

spurious unused warning of local given for CanEqual with -Wunused:locals and -language:strictEquality #17762

Closed
felher opened this issue Jun 3, 2023 · 5 comments · Fixed by #18641
Assignees
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug

Comments

@felher
Copy link
Contributor

felher commented Jun 3, 2023

3.3 is awesome, thank you for bringing warnings back and all your hard work! ❤️
There seems to be a small interaction problem with what is regarded unused and -language:strictEquality though:

Compiler version

3.3.0

Minimized code

CompilerOptions:

  • -language:strictEquality
  • -Wunused:locals
class SomeType

def testIt(st1: SomeType, st2: SomeType): Boolean =
  given CanEqual[SomeType, SomeType] = CanEqual.derived
  st1 == st2

Output

A warning that the given definition is unused - or a compiler error that SomeType can not be compare with itself when removed

Expectation

It should not warn since the given CanEqual[...] is required by the compiler under -language:strictEquality

Scastie

https://scastie.scala-lang.org/i6Osmdc1SSK9FQlN3a65dA

@felher felher added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 3, 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 4, 2023
@aflierl
Copy link

aflierl commented Jun 20, 2023

I would like to remark that something similar happens when using -Wunused:imports if the given is imported from somewhere else (like another package), e.g.:

object OneModule:
  import AnotherModule.given

  def meep =  Meep("meep") == Meep("moop")

final case class Meep(moop: String)

object AnotherModule:
  given CanEqual[Meep, Meep] = CanEqual.derived

Or is this / should this be another bug?

@lukestephenson
Copy link

lukestephenson commented Jul 25, 2023

Also observed the same issue. Created a minimal repo (before I spotted the issue was already raised) showing the compilation failure for both:

  • imports of givens not working
  • given within a function being reported as unused.

Thanks (agree with the earlier sentiment that 3.3 is great - thanks for the improvements!)

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

joan38 commented Oct 2, 2023

Hey! Getting hit by the same issue here but with -Wunused:imports and importing the given CanEqual.
I also have -Xfatal-warnings so it makes it impossible to make the compiler happy because either it complains that the CanEqual is missing or that the import is unused.

@joan38
Copy link
Contributor

joan38 commented Oct 10, 2023

Nice! Is this targeted to be released in 3.3.2?

@Kordyjan
Copy link
Contributor

Is this targeted to be released in 3.3.2?

Yes.

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

Successfully merging a pull request may close this issue.

7 participants