Skip to content

Extension method isn't resolved but can be called directly #22736

Open
@road21

Description

@road21

Compiler version

3.3.5 LTS, 3.6.3

Minimized code

enum Child:
  case Son(name: String)

extension [A](x: A)(using Child <:< A) def boo: Unit = println("")
// extension [A >: Child](x: A) def boo: Unit = println("") // works

boo(Child.Son("bob"))  // compiling
(Child.Son("bob")).boo // not compiling

val x = Child.Son("bob")
x.boo // compiling

Output

Compiler error:

value boo is not a member of Playground.Child.Son

Expectation

According the following rule from the doc about extension methods:

The selection is rewritten to m[Ts](e) and typechecked, using the following slight modification of the name resolution rules...

I expect that the behavior for direct call and as-field would be the same.

I understand, that there is a difference in type inference: compiler infers type Son in second case. But type Son is very specific, I feel like it shouldn't be inferred for enum:

Generally, the type of a enum case constructor application will be widened to the underlying enum type, unless a more specific type is expected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions