Skip to content

Extension methods can't be chained when the the first has an explicit type parameter but no other parameters #6900

Closed
@travisbrown

Description

@travisbrown

minimized code

given [A] { def (a: A) foo[C]: C => A = _ => a }

1.foo[String].foo[String]

Fails to compile with:

1 |1.foo[String].foo[String]
  |^^^^^
  |value foo is not a member of Int - did you mean Int(1).+?.
  |An extension method was tried, but could not be fully constructed:
  |
  |    foo_of_A_given[Int].foo[String](1)

expectation

It should compile.

Note that defining an intermediate val works:

scala> val result = 1.foo[String]
val result: String => Int = foo_of_A_given$$Lambda$10912/547292714@e0b8c6a

scala> result.foo[String]
val res0: String => String => Int = foo_of_A_given$$Lambda$10912/547292714@6038a356

As does letting C be inferred:

scala> 1.foo.foo
val res1: Any => Any => Int = foo_of_A_given$$Lambda$10913/181900017@5642dd8c

It's also just fine if you add an empty parameter list:

scala> given [A] { def (a: A) bar[C](): C => A = _ => a }
// defined class bar_of_A_given

scala> 1.bar[String]().bar[String]()
val res2: String => String => Int = bar_of_A_given$$Lambda$10914/798714466@2c6c2f2e

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions