Skip to content

Overriding Java method with varargs under -Yexplicit-nulls compiler error #13486

Closed
@pweisenburger

Description

@pweisenburger

Hi, given the following code that overrides a Java method under -Yexplicit-nulls:

class MyPrintStream extends java.io.PrintStream(??? : java.io.OutputStream):
  override def printf(format: String | Null, args: Array[? <: Object | Null])
  : java.io.PrintStream | Null = ???

The compiler produces the following error message:

Name clash between defined and inherited member:
def printf(x$0: String | Null, x$1: Array[? <: Object | Null])
  : java.io.PrintStream | Null in class PrintStream and
override def printf(format: String | Null, args: Array[? <: Object | Null])
  : java.io.PrintStream | Null in class MyPrintStream
have the same type after erasure.

It should not be an error that both methods have the same type since one is supposed to override the other.

As @smarter noted on Gitter, this might be a confusion between varargs and Array arguments.

Tested with Scala 3.0.2 and 3.1.1-RC1-bin-20210907-a47a81a-NIGHTLY

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions