Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java compilation errors depending on naming of Scala type parameters #6057

Closed
scabug opened this issue Jul 11, 2012 · 3 comments
Closed

Java compilation errors depending on naming of Scala type parameters #6057

scabug opened this issue Jul 11, 2012 · 3 comments
Milestone

Comments

@scabug
Copy link

scabug commented Jul 11, 2012

The following Scala program compiles and runs without errors:

trait MyTrait[T] {
    def map[U](t: T, u: MyArgument[U]) : MyArgument[U] = u
}

class MyArgument[U](u: U) {}

class MyClass[U] extends MyTrait[U] {}

class MyClassRenamedTypes[U2] extends MyTrait[U2] {}

object MyClass {
    def main(args: Array[String]) {
        new MyClass[Int].map(1, new MyArgument("String"))
        new MyClassRenamedTypes[Int].map(1, new MyArgument("String"))
    }
}

Consider a Java implementation of the same main main() method:

public class JavaTypeParam {
    public static void main(String[] args) {
        // This should compile:
        new MyClassRenamedTypes<Integer>().map(1, new MyArgument<String>("String"));
        // This fails:
        new MyClass<Integer>().map(1, new MyArgument<String>("String"));
    }
}

Javac fails to compile the last line of this main() method:
{noformat}
JavaTypeParam.java:6: map(U,MyArgument) in MyClass<java.lang.Integer> cannot be applied to (int,MyArgument<java.lang.String>)
new MyClass().map(1, new MyArgument("String"));
^{noformat}

The only difference between MyClass and MyClassRenamedTypes is the name of the type parameter. It looks like type parameters in different namespaces are colliding.

Interestingly, everything compiles if MyArgument[U] is replaced by U. It also compiles if the definition of MyTrait.map() is changed to

{code}
def map[U](u: MyArgument[U]) : MyArgument[U] = u{code}

@scabug
Copy link
Author

scabug commented Jul 11, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6057?orig=1
Reporter: Josh Rosen (joshrosen)
Affected Versions: 2.9.2

@scabug
Copy link
Author

scabug commented Jul 11, 2012

@adriaanm said:
reproduced on 2.10.0-M4

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@som-snytt
Copy link

Reproduced on 2.11.12, fixed by 2.12.9, recent Java 8, 11.

@scala scala deleted a comment from scabug Feb 13, 2020
@SethTisue SethTisue modified the milestones: Backlog, 2.12.9 Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants