Skip to content

Nested classes' generic signatures for mixin forwarders conflicts type parameter names #24619

@tanishiking

Description

@tanishiking

#24567 fixed generic signatures for mixin forwarders that conflicted with parent class type parameters #24134. However, as @hamzaremmal mentioned, we still have a name clash when the generic class is nested. We need to collect the type parameters of all enclosing classes.
#24567 (comment)

Compiler Version: 3.8.1-RC1-bin-20251202-9eb843d-NIGHTLY

class Container[A]:
  abstract class JavaPartialFunction[B] extends PartialFunction[A, B]
public class Main {
    public static void main(String[] args) {
        Container<String> container = new Container<>();
        Container<String>.JavaPartialFunction<Integer> pf = container.new JavaPartialFunction<Integer>() {
            @Override
            public boolean isDefinedAt(String x) {
                return x != null && !x.isEmpty();
            }
            @Override
            public Integer apply(String x) {
                return x.length();
            }
        };
    }
}
$ scala-cli compile . -S 3.8.1-RC1-bin-20251202-9eb843d-NIGHTLY
[error] ./Main.java:4:106
[error] name clash: compose(scala.Function1<A,java.lang.String>) in scala.Function1 and compose(scala.Function1<A,A>) in Container.JavaPartialFunction have the same erasure, yet neither overrides the other
Compilation failed

and the bytecode for JavaPartialFunction is like

public abstract class Container$JavaPartialFunction<B> implements scala.PartialFunction<A, B> {
  // ...
  public <A> scala.Function1<A, B> compose(scala.Function1<A, A>);

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions