Skip to content

Bug overriding varargs method defined both in Scala class and Java interface, while also narrowing return type #11944

Open
@mkurz

Description

@mkurz

reproduction steps

(see #11944 (comment) for minimal repro)

Clone my fork of the Play Framework and checkout the addAttrs branch (according pull request):

git clone [email protected]:mkurz/playframework.git
git checkout addAttrs

Try to compile:

sbt compile

problem

Because of this commit compilation fails:

[error] ./core/play/src/main/scala/play/core/j/JavaHelpers.scala:258:7: incompatible type in overriding
[error] def addAttrs(entries: play.libs.typedmap.TypedEntry[_]*): play.mvc.Http.Request (defined in trait Request)
[error]   with override def addAttrs(entries: play.libs.typedmap.TypedEntry[_]*): play.mvc.Http.RequestHeader (defined in class RequestHeaderImpl);
[error]  found   : (entries: play.libs.typedmap.TypedEntry[_]*)play.mvc.Http.RequestHeader
[error]  required: (entries: play.libs.typedmap.TypedEntry[_]*)play.mvc.Http.Request
[error] class RequestImpl(request: Request[RequestBody]) extends RequestHeaderImpl(request) with JRequest {
[error]       ^

I am pretty sure this is a bug in the Scala compiler.

All the commit does it adds the method addAttrs with a varargs param to Java interfaces and Scala classes that extend from those interfaces (and from each other).
If you look at the commit you will see there is an existing addAttr method (without s and the end) already, just above the addAttrs method I want to add. This existing method follows the exact same scheme (e.g. return type) like the method I want to add. For addAttr the code compiles, addAttrs makes it fail. That's why I think this has to be a bug in the Scala compiler which is caused by the varargs param.

Effects Scala 2.13.1 and 2.12.11.
I am using AdoptOpenJDK 11, also tried with 8.

expectation

Code compiles.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions