Skip to content

compiler should generate error "method foo1 in class C must be called with () argument" for inherited nullary method without arguments that has extra overloaded function in child class #21207

Open
@unkarjedy

Description

@unkarjedy

Scala 3.3.3 (same with 3.5.1-RC1)

I am using the language specification at 1 & 2 & 3.
Use the code below:
(It might be convenient to use worksheet to see the evaluation result)

trait T { // NOTE: it can abstract class or class, it doesn't matter
  def foo1(): Int = 1
  def foo2(x: Int): Int = 33
}

class C extends T {
  def foo1(x: Int): Int = 11
  def foo2(): Int = 33

  def foo3(): Int = 2
  def foo3(x: Int): Int = 22
}

val c = new C
val x1 = c.foo1
val x2 = c.foo2
val x3 = c.foo3

Notice that c.foo1 compiles fine and evaluates to 1

However for c.foo2 and c.foo3 compiler generates a syntax error: method foo3 in class C must be called with () argument

image

According to spec the compiler should also generate an error for c.foo1:
method foo1 in class C must be called with () argument
The exclusion can be Java methods, but foo1 is not defined in Java and not overridden.

Excluded from this rule are methods that are defined in Java or that override methods defined in Java.

Note that if you remove def foo1(x: Int): Int = 11 then the error IS generated.
It seems like the check if foo1 has some parameters somehow interleaves with overloading resolution and is done before def foo1(x: Int): Int is discarded

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