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

Recursive Java generics crash the compiler

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.7.2
    • Component/s: Misc Compiler
    • Labels:
      None
    • Environment:

      classfile parser generics

      Description

      A Java generic class that refers to its own type crashes the classfile parser.

      Java:

      interface Field<A> {
      }
      
      public class Amount<Q> extends Object 
          implements Field<Amount<?>> {
      }
      

      Scala:

      abstract class Foo {
        val x: Amount[Foo]
      }
      

      The classfile parser will try to resolve the `Amount` class type while parsing `Amount`, resulting in a busy assertion:

      Exception in thread "main" java.lang.AssertionError: assertion failed: internal error: illegal class file dependency in classes/Amount.class
              at scala.Predef$$.assert(Predef.scala:92)
              at scala.tools.nsc.symtab.classfile.ClassfileParser.parse(ClassfileParser.scala:60)
              at scala.tools.nsc.symtab.SymbolLoaders$$ClassfileLoader$$$$anonfun$$doComplete$$3.apply(SymbolLoaders.scala:287)
              at scala.tools.nsc.symtab.SymbolLoaders$$ClassfileLoader$$$$anonfun$$doComplete$$3.apply(SymbolLoaders.scala:287)
              at scala.tools.nsc.symtab.SymbolLoaders.completeClassfile(SymbolLoaders.scala:278)
              at scala.tools.nsc.symtab.SymbolLoaders$$ClassfileLoader.doComplete(SymbolLoaders.scala:286)
              at scala.tools.nsc.symtab.SymbolLoaders$$SymbolLoader.complete(SymbolLoaders.scala:80)
              at scala.tools.nsc.symtab.SymbolLoaders$$SymbolLoader.load(SymbolLoaders.scala:100)
              at scala.tools.nsc.symtab.Symbols$$Symbol.typeParams(Symbols.scala:655)
              at scala.tools.nsc.symtab.Types$$TypeMap.mapOver(Types.scala:2262)
              at scala.tools.nsc.symtab.Types$$ForEachTypeTraverser.traverse(Types.scala:2997)
              at scala.tools.nsc.symtab.Types$$Type.foreach(Types.scala:470)
              at scala.tools.nsc.symtab.Types$$class.existentialAbstraction(Types.scala:2083)
              at scala.tools.nsc.symtab.SymbolTable.existentialAbstraction(SymbolTable.scala:12)
              at scala.tools.nsc.symtab.classfile.ClassfileParser.processClassType$$1(ClassfileParser.scala:509)
              at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$$1(ClassfileParser.scala:524)
              at scala.tools.nsc.symtab.classfile.ClassfileParser.processClassType$$1(ClassfileParser.scala:503)
              at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$$1(ClassfileParser.scala:524)
              at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$$tools$$nsc$$symtab$$classfile$$ClassfileParser$$$$sigToType(ClassfileParser.scala:583)
              at scala.tools.nsc.symtab.classfile.ClassfileParser.parseAttribute$$1(ClassfileParser.scala:606)
              at scala.tools.nsc.symtab.classfile.ClassfileParser$$$$anonfun$$parseAttributes$$1.apply(ClassfileParser.scala:770)
              at scala.tools.nsc.symtab.classfile.ClassfileParser$$$$anonfun$$parseAttributes$$1.apply(ClassfileParser.scala:770)
              at scala.Iterator$$class.foreach(Iterator.scala:395)
              at scala.RandomAccessSeq$$$$anon$$12.foreach(RandomAccessSeq.scala:138)
              at scala.Iterable$$class.foreach(Iterable.scala:256)
              at scala.Range.foreach(Range.scala:30)
              at scala.tools.nsc.symtab.classfile.ClassfileParser.parseAttributes(ClassfileParser.scala:770)
              at scala.tools.nsc.symtab.classfile.ClassfileParser.parseClass(ClassfileParser.scala:357)
              at scala.tools.nsc.symtab.classfile.ClassfileParser.parse(ClassfileParser.scala:84)
              at scala.tools.nsc.symtab.SymbolLoaders$$ClassfileLoader$$$$anonfun$$doComplete$$3.apply(SymbolLoaders.scala:287)
              at scala.tools.nsc.symtab.SymbolLoaders$$ClassfileLoader$$$$anonfun$$doComplete$$3.apply(SymbolLoaders.scala:287)
              at scala.tools.nsc.symtab.SymbolLoaders.completeClassfile(SymbolLoaders.scala:278)
              at scala.tools.nsc.symtab.SymbolLoaders$$ClassfileLoader.doComplete(SymbolLoaders.scala:286)
              at scala.tools.nsc.symtab.SymbolLoaders$$SymbolLoader.complete(SymbolLoaders.scala:80)
              at scala.tools.nsc.symtab.SymbolLoaders$$SymbolLoader.load(SymbolLoaders.scala:100)
              at scala.tools.nsc.symtab.Symbols$$Symbol.exists(Symbols.scala:386)
              at scala.tools.nsc.typechecker.Typers$$Typer.qualifies$$1(Typers.scala:2782)
              at scala.tools.nsc.typechecker.Typers$$Typer.typedIdent$$1(Typers.scala:2797)
              at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3172)
              at scala.tools.nsc.typechecker.Typers$$Typer.typedAppliedTypeTree$$1(Typers.scala:2915)
              at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:3195)
              at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3243)
              at scala.tools.nsc.typechecker.Typers$$Typer.typedType(Typers.scala:3312)
              at scala.tools.nsc.typechecker.Namers$$Namer.typeSig(Namers.scala:851)
              at scala.tools.nsc.typechecker.Namers$$Namer$$$$anonfun$$getterTypeCompleter$$1.apply(Namers.scala:436)
              at scala.tools.nsc.typechecker.Namers$$Namer$$$$anonfun$$getterTypeCompleter$$1.apply(Namers.scala:434)
              at scala.tools.nsc.typechecker.Namers$$$$anon$$1.complete(Namers.scala:1009)
              at scala.tools.nsc.symtab.Symbols$$Symbol.info(Symbols.scala:508)
              at scala.tools.nsc.symtab.Symbols$$Symbol.initialize(Symbols.scala:622)
              at scala.tools.nsc.typechecker.Typers$$Typer.addGetterSetter(Typers.scala:1088)
              at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$10.apply(Typers.scala:1163)
              at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$10.apply(Typers.scala:1163)
              at scala.List.flatMap(List.scala:1120)
              at scala.tools.nsc.typechecker.Typers$$Typer.typedTemplate(Typers.scala:1163)
              at scala.tools.nsc.typechecker.Typers$$Typer.typedClassDef(Typers.scala:1039)
              at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:2972)
              at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3243)
              at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3280)
              at scala.tools.nsc.typechecker.Typers$$Typer.typedStat$$1(Typers.scala:1540)
              at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$19.apply(Typers.scala:1585)
              at scala.tools.nsc.typechecker.Typers$$Typer$$$$anonfun$$19.apply(Typers.scala:1585)
              at scala.List$$.loop$$1(List.scala:293)
              at scala.List$$.mapConserve(List.scala:310)
              at scala.tools.nsc.typechecker.Typers$$Typer.typedStats(Typers.scala:1585)
              at scala.tools.nsc.typechecker.Typers$$Typer.typed1(Typers.scala:2968)
              at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3243)
              at scala.tools.nsc.typechecker.Typers$$Typer.typed(Typers.scala:3280)
              at scala.tools.nsc.typechecker.Analyzer$$typerFactory$$$$anon$$2.apply(Analyzer.scala:40)
              at scala.tools.nsc.Global$$GlobalPhase.applyPhase(Global.scala:257)
              at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$run$$1.apply(Global.scala:243)
              at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$run$$1.apply(Global.scala:243)
              at scala.Iterator$$class.foreach(Iterator.scala:395)
              at scala.collection.mutable.ListBuffer$$$$anon$$1.foreach(ListBuffer.scala:266)
              at scala.tools.nsc.Global$$GlobalPhase.run(Global.scala:243)
              at scala.tools.nsc.Global$$Run.compileSources(Global.scala:556)
              at scala.tools.nsc.Global$$Run.compile(Global.scala:641)
              at scala.tools.nsc.Main$$.process(Main.scala:84)
              at scala.tools.nsc.Main$$.main(Main.scala:98)
              at scala.tools.nsc.Main.main(Main.scala)
      

        Issue Links

          Activity

          Hide
          Martin Odersky added a comment -

          fixed in r15139

          Show
          Martin Odersky added a comment - fixed in r15139
          Hide
          Martin Odersky added a comment -

          Milestone next_bugfix deleted

          Show
          Martin Odersky added a comment - Milestone next_bugfix deleted

            People

            • Assignee:
              Martin Odersky
              Reporter:
              Iulian Dragos
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development