Scala Programming Language
  1. Scala Programming Language
  2. SI-5696

Compiler exception on new anonymous class creation (with apply call)

    Details

      Description

      class TestApply {
        class G(y: Int) {
          def apply(x: Int) = 1
        }
      
        new G(1)(2) {}
      }
      

      java.lang.AssertionError: assertion failed: type can't convert from UNIT to REF(class TestApply$G) in unit Main.scala at source-C:\Users\Alexander.Podkhalyuz\IdeaProjects\LiftMavenTest\src\scalatest\Main.scala,line-8,offset=109
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.adapt(GenICode.scala:1149)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:1131)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadQualifier(GenICode.scala:1175)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:921)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genStat(GenICode.scala:174)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genStat$1.apply(GenICode.scala:143)
      at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
      at scala.collection.immutable.List.foldLeft(List.scala:45)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genStat(GenICode.scala:143)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:1052)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:114)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:69)
      at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
      at scala.collection.immutable.List.foreach(List.scala:45)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:69)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:136)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:88)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:79)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:65)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.apply(GenICode.scala:61)
      at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:329)
      at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:297)
      at scala.collection.Iterator$class.foreach(Iterator.scala:660)
      at scala.collection.mutable.ListBuffer$$anon$1.foreach(ListBuffer.scala:316)
      at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:297)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.run(GenICode.scala:54)
      at scala.tools.nsc.Global$Run.compileSources(Global.scala:953)
      at scala.tools.nsc.Global$Run.compile(Global.scala:1038)
      at scala.tools.nsc.Main$.process(Main.scala:106)
      at scala.tools.nsc.Main$.main(Main.scala:123)
      at scala.tools.nsc.Main.main(Main.scala)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.jetbrains.plugins.scala.compiler.rt.ClassRunner.main(ClassRunner.java:46)
      Exception in thread "main" java.lang.reflect.InvocationTargetException

        Activity

        Hide
        Hubert Plociniczak added a comment -

        Still fails in trunk.

        Show
        Hubert Plociniczak added a comment - Still fails in trunk.
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/698
        Show
        Jason Zaugg added a comment - Fixed in https://github.com/scala/scala/commit/fc6ea96f1946712a889b7db50a520be49ea2e208
        Hide
        Daniel Sobral added a comment -

        Is new G(1)(2) still legal? I'm pretty sure I have code like that.

        Show
        Daniel Sobral added a comment - Is new G(1)(2) still legal? I'm pretty sure I have code like that.
        Hide
        Jason Zaugg added a comment -

        Yep.

        
        scala> class G(y: Int) {
             |     def apply(x: Int) = 1
             |   }
        defined class G
        
        scala> new G(0)(0)
        res0: Int = 1
        
        scala> new G(0)(0) {}
        <console>:9: error: too many argument lists for constructor invocation
                      new G(0)(0) {}
                          ^
        
        Show
        Jason Zaugg added a comment - Yep. scala> class G(y: Int) { | def apply(x: Int) = 1 | } defined class G scala> new G(0)(0) res0: Int = 1 scala> new G(0)(0) {} <console>:9: error: too many argument lists for constructor invocation new G(0)(0) {} ^

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Alexander
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development