Aladdin - Scala Bugtracking
[#987] project: compiler priority: low category: bug
submitter assigned to status date submitted
Nikolay Martin fixed 2007-03-12 08:51:34.0
subject [contrib #362] NullPointerException in Type.closurePos
code
// tested using Scala compiler version 2.4.0-RC1 -- (c) 2002-2007 LAMP/EPFL

// Many thanks to all at LAMP for the work that goes into Scala.


class A {}

trait B[T <: B[T]] requires T {}

abstract class C extends A with B[C]
{
    protected val data: List[Int]
}

class E extends D
{
    val data = Nil
}

class F extends D
{
    val data = Nil
}

abstract class D extends C with B[D] {}


/* With the code as submitted, the compiler crashes:-

error: the type intersection B[D] with B[C] is malformed
 --- because ---
no common type instance of base types B[C] and B[D] exists
class E extends D

^
error: illegal inheritance;
 self-type F does not conform to D's selftype D
class F extends D

                ^
Exception in thread "main" java.lang.NullPointerException
	at scala.tools.nsc.symtab.Types$Type.closurePos(Types.scala:335)
	at scala.tools.nsc.symtab.Types$CompoundType.isNew$0(Types.scala:781)
	at scala.tools.nsc.symtab.Types$CompoundType.addMixinBaseClasses$0(Types.scala:790)
	at scala.tools.nsc.symtab.Types$CompoundType.computeBaseClasses$0(Types.scala:792)
	at scala.tools.nsc.symtab.Types$CompoundType.baseClasses(Types.scala:802)
	at scala.tools.nsc.symtab.Types$TypeRef.baseClasses(Types.scala:1087)
	at scala.tools.nsc.symtab.Types$SubType.baseClasses(Types.scala:519)
	at scala.tools.nsc.symtab.Types$Type.findMember(Types.scala:422)
	at scala.tools.nsc.symtab.Types$Type.member(Types.scala:182)
	at scala.tools.nsc.typechecker.Typers$Typer.typedIdent$0(Typers.scala:1853)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:2332)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2417)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2461)
	at scala.tools.nsc.typechecker.Typers$Typer.computeType(Typers.scala:2493)
	at scala.tools.nsc.typechecker.Namers$Namer.typeSig(Namers.scala:607)
	at scala.tools.nsc.typechecker.Namers$Namer$$anon$0.complete(Namers.scala:336)
	at scala.tools.nsc.symtab.Symbols$Symbol.info(Symbols.scala:401)
	at scala.tools.nsc.symtab.Symbols$Symbol.initialize(Symbols.scala:509)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1938)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2417)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2450)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$0(Typers.scala:1339)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$55.apply(Typers.scala:1362)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$55.apply(Typers.scala:1362)
	at scala.List$.loop$0(List.scala:243)
	at scala.List$.mapConserve(List.scala:260)
	at scala.List$.loop$0(List.scala:247)
	at scala.List$.mapConserve(List.scala:260)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:1362)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:973)
	at scala.tools.nsc.typechecker.Typers$Typer.typedClassDef(Typers.scala:870)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1947)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2417)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2450)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$0(Typers.scala:1339)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$55.apply(Typers.scala:1362)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$55.apply(Typers.scala:1362)
	at scala.List$.loop$0(List.scala:243)
	at scala.List$.mapConserve(List.scala:260)
	at scala.List$.loop$0(List.scala:247)
	at scala.List$.mapConserve(List.scala:260)
	at scala.List$.loop$0(List.scala:247)
	at scala.List$.mapConserve(List.scala:260)
	at scala.List$.loop$0(List.scala:247)
	at scala.List$.mapConserve(List.scala:260)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:1362)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1943)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2417)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2450)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$1.apply(Analyzer.scala:38)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:231)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:220)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:220)
	at scala.Iterator$class.foreach(Iterator.scala:380)
	at scala.collection.mutable.ListBuffer$$anon$0.foreach(ListBuffer.scala:245)
	at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:220)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:488)
	at scala.tools.nsc.Global$Run.compile(Global.scala:559)
	at scala.tools.nsc.Main$.process(Main.scala:57)
	at scala.tools.nsc.Main$.main(Main.scala:79)
	at scala.tools.nsc.Main.main(Main.scala)

*/



/*
If we replace
  abstract class C extends A with B[C]
with
  abstract class C extends A
we have successful compilation.
*/

/*
If we omit class F:-

error: the type intersection B[D] with B[C] is malformed
 --- because ---
no common type instance of base types B[C] and B[D] exists
class E extends D
^
one error found
*/

/*
If we move the definition of class D so that it appears in the source file between the definitions of C and E
(not an ideal workaround as the definitions were from different files)

error: the type intersection B[D] with B[C] is malformed
 --- because ---
no common type instance of base types B[C] and B[D] exists
abstract class D extends C with B[D] {}
         ^

error: the type intersection D with scala.ScalaObject{def thi
s: <?>; def data: <?>; private val data: <?>} is malformed
 --- because ---
no common type instance of base types B[D] and B[C] exists
class E extends D
^

error: the type intersection D with scala.ScalaObject{def thi
s: <?>; def data: <?>; private val data: <?>} is malformed
 --- because ---
no common type instance of base types B[D] and B[C] exists
class F extends D
^
three errors found

*/
what happened
Exception in thread "main" java.lang.NullPointerException
	at scala.tools.nsc.symtab.Types$Type.closurePos(Types.scala:335)
what expected compile error, e.g. as occurs when we move the definition of D to between the definitions of C and E
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-03-12 08:52:05.0
contribution #362
Martin  edited on  2007-03-12 13:04:17.0