Skip to content

Unhelpful warning: Extension method f will never be selected from type <none> #22706

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

Closed
OndrejSpanel opened this issue Mar 4, 2025 · 0 comments · Fixed by #22708
Closed

Unhelpful warning: Extension method f will never be selected from type <none> #22706

OndrejSpanel opened this issue Mar 4, 2025 · 0 comments · Fixed by #22708
Assignees
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Milestone

Comments

@OndrejSpanel
Copy link
Member

OndrejSpanel commented Mar 4, 2025

Compiler version

3.7.0-RC1-bin-20250228-e592b37-NIGHTLY

Minimized code

A bit extended version of #22705

object Native {
  class O {
    def f: String = "F"
  }
  class M extends O
}

object Types {
  opaque type N = Native.O
  opaque type GS = Native.M

  type S = N | GS

  object S:
    def apply(): S = new N

  extension (s: S)
    def f: String = "S"
}

import Types.*

object Main {
  def main(args: Array[String]): Unit = {
    val v: S = S()
    println(v.f)
  }
}

Output

Extension method f will never be selected from type <none>
because <none> already has a member with the same name and compatible parameter types.
    def f: String = "S"

Expectation

The warning should not reference a type as <none>.

@OndrejSpanel OndrejSpanel added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 4, 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 Mar 4, 2025
@som-snytt som-snytt self-assigned this Mar 4, 2025
@WojciechMazur WojciechMazur added this to the 3.7.0 milestone Mar 11, 2025
tgodzik pushed a commit to scala/scala3-lts that referenced this issue Apr 24, 2025
Fixes scala#22705
Fixes scala#22706 
Fixes scala#22727 

Follow-up to scala#22502 by inserting a
`dealias` when arriving at `target` type.

Refactored the body of `hidden` to make it easier to read. Adjusted the
doc for the same reason.

As a reminder to self, the original reason for special handling of
aliases was due to subclassing, but overrides are excluded. (One could
restore that warning for edge cases.)

The long doc explaining the handling of leading implicits is moved to
the end (as an appendix).

Despite best efforts, I was unable to make the doc longer than the code.
[Cherry-picked d362492]
tgodzik pushed a commit to scala/scala3-lts that referenced this issue Apr 24, 2025
Fixes scala#22705
Fixes scala#22706 
Fixes scala#22727 

Follow-up to scala#22502 by inserting a
`dealias` when arriving at `target` type.

Refactored the body of `hidden` to make it easier to read. Adjusted the
doc for the same reason.

As a reminder to self, the original reason for special handling of
aliases was due to subclassing, but overrides are excluded. (One could
restore that warning for edge cases.)

The long doc explaining the handling of leading implicits is moved to
the end (as an appendix).

Despite best efforts, I was unable to make the doc longer than the code.
[Cherry-picked d362492]
tgodzik pushed a commit to scala/scala3-lts that referenced this issue Apr 25, 2025
Fixes scala#22705
Fixes scala#22706 
Fixes scala#22727 

Follow-up to scala#22502 by inserting a
`dealias` when arriving at `target` type.

Refactored the body of `hidden` to make it easier to read. Adjusted the
doc for the same reason.

As a reminder to self, the original reason for special handling of
aliases was due to subclassing, but overrides are excluded. (One could
restore that warning for edge cases.)

The long doc explaining the handling of leading implicits is moved to
the end (as an appendix).

Despite best efforts, I was unable to make the doc longer than the code.
[Cherry-picked d362492]
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.

3 participants