Skip to content

Compile error when call an extension method directly on the result of "calling a nullary version of overloaded method with type arguments and without parenthesis" #14729

Closed
@jiftechnify

Description

@jiftechnify

Compiler version

3.1.2-RC2

Minimized code

class Foo():
  def normal: Unit = println("normal")

extension (f: Foo) 
  def ext: Unit = println("ext")

object Bar:
  def makeFoo[A]: Foo = Foo()
  def makeFoo[A](s: String): Foo = Foo()

def tests: Unit =
  Bar.makeFoo[Int].ext // error

  (Bar.makeFoo[Int]).ext // error

  val foo = Bar.makeFoo[Int]
  foo.ext // ok

  Bar.makeFoo[Int].normal // ok

Output

[error] -- [E134] Type Error: <snip>
[error] 35 |  Bar.makeFoo[Int].ext()
[error]    |  ^^^^^^^^^^^
[error]    |None of the overloaded alternatives of method makeFoo in object Bar with types
[error]    | [A](s: String): com.example.Foo
[error]    | [A] => com.example.Foo
[error]    |match type arguments [Int] and expected type ?{ ext: ? }
[error] -- [E134] Type Error: <snip>
[error] 38 |  (Bar.makeFoo[Int]).ext()
[error]    |   ^^^^^^^^^^^
[error]    |None of the overloaded alternatives of method makeFoo in object Bar with types
[error]    | [A](s: String): com.example.Foo
[error]    | [A] => com.example.Foo
[error]    |match type arguments [Int] and expected type ?{ ext: ? }

Expectation

Compile with no error.

Note

Confirmed that codes below compile successfully.

class Foo():
  def normal: Unit = println("normal")

extension (f: Foo) 
  def ext(): Unit = println("ext")

object WithParen:
  def makeFoo[A](): Foo = Foo()
  def makeFoo[A](s: String): Foo = Foo()

object NoTypeParam:
  def makeFoo: Foo = Foo()
  def makeFoo(s: String): Foo = Foo()

object NoOverload:
  def makeFoo[A]: Foo = Foo()

def ok: Unit =
  WithParen.makeFoo[Int]().ext
  NoTypeParam.makeFoo.ext
  NoOverload.makeFoo[Int].ext

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions