Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-5125

Compilation errors when mixing @varargs and higher-order functions

    Details

      Description

      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).

        Attachments

          Issue Links

            Activity

            Hide
            renato Renato Cavalcanti added a comment -

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

            Show
            renato Renato Cavalcanti added a comment - Small typo on my description. Should read: "... compilation of A.java will fail if C.g() or O.g() are uncommented"
            Show
            retronym Jason Zaugg added a comment - https://github.com/scala/scala/pull/587

              People

              • Assignee:
                retronym Jason Zaugg
                Reporter:
                renato Renato Cavalcanti
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: