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

Compilation errors when mixing @varargs and higher-order functions #5125

Closed
scabug opened this issue Oct 28, 2011 · 3 comments

Comments

@scabug
Copy link

commented Oct 28, 2011

Classes or Objects containing methods annotated with @VarArgs and higher-order functions (on return) will generate compilation errors when used form Java code.

In the following example, compilation of A.java will fail if C.g() or O.g() are uncommented

// C.scala
class C {
    @scala.annotation.varargs
    def f(values:String*) = println("Calling C.f(): "  + values) 
    // uncommenting that line will cause an AssertionError
    // def g(): String => Int = s => s.hashCode 
}
// O.scala
object O {
    def instance = this
    @scala.annotation.varargs
    def f(values:String*) = println("Calling O.f(): " + values)
    // uncommenting g() results in errors in A.java
    // def g(): String => Int = s => s.hashCode
}
// A.java
public class A {
    public static void main(String[] args) {
        // uncommenting  C.g() will generate AssertionError
        new C().f("a", "b", "c");
        // uncommenting O.g() will generate NoSuchMethodError
        O.f("a", "b", "c");  
        // uncommenting O.g() will generate "f(Seq<String>) in O$ cannot be applied to (String,String,String)"
        O.instance().f("a", "b", "c");
    }
}

In the attachment, you'll find a small sbt project containing the code.
I've tried it with 2.9.1 and the 2.10.0-SNAPSHOT (from 28 Oct).

@scabug

This comment has been minimized.

Copy link
Author

commented Oct 28, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5125?orig=1
Reporter: Renato Cavalcanti (renato)
Affected Versions: 2.9.1
Other Milestones: 2.10.0
Attachments:

  • varargs.zip (created on Oct 28, 2011 8:23:39 PM UTC, 2509 bytes)
@scabug

This comment has been minimized.

Copy link
Author

commented Oct 28, 2011

Renato Cavalcanti (renato) said:
Small typo on my description. Should read:
"... compilation of A.java will fail if C.g() or O.g() are uncommented"

@scabug

This comment has been minimized.

Copy link
Author

commented May 20, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.