Aladdin - Scala Bugtracking
[#712] project: compiler priority: low category: bug
submitter assigned to status date submitted
Sean Martin fixed 2006-08-22 14:05:18.0
subject implicit def NPE
code
trait A {
  type Node <: NodeImpl;
  implicit def coerce(n : NodeImpl) = n.self;
  trait NodeImpl {
    def self : Node;
  }
}
trait B extends A {
  type Parent <: ParentImpl;
  implicit def coerce(p : ParentImpl) = p.self;
  trait ParentImpl;
  type Symbol;
  trait SymbolImpl {
    def scope : Int;
  }
  implicit def coerceSym(sym : Symbol) : SymbolImpl;
  var s : Symbol = null;
  val s_scope = s.scope;
}
what happened
sean-mcdirmids-computer:~/workspace/test10/src mcdirmid$ ../../scala/build/quick/bin/scalac -d ../bin test/B.sca\
la
Exception in thread "main" java.lang.NullPointerException
	at scala.tools.nsc.typechecker.Typers$Typer.searchImplicit$0(Typers.scala:1940)
	at scala.tools.nsc.typechecker.Typers$Typer.inferImplicit(Typers.scala:1960)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$inferView(Typers.scala:66\
)
	at scala.tools.nsc.typechecker.Typers$Typer.inferView(Typers.scala:75)
	at scala.tools.nsc.typechecker.Typers$Typer.adaptToMember(Typers.scala:513)
	at scala.tools.nsc.typechecker.Typers$Typer.adaptToName(Typers.scala:522)
	at scala.tools.nsc.typechecker.Typers$Typer.typedSelect$0(Typers.scala:1298)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1694)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1763)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1790)
	at scala.tools.nsc.typechecker.Typers$Typer.computeType(Typers.scala:1823)
	at scala.tools.nsc.typechecker.Namers$Namer.methodSig(Namers.scala:419)
	at scala.tools.nsc.typechecker.Namers$Namer.scala$tools$nsc$typechecker$Namers$Namer$$typeSig(Namers.scala:488)\

	at scala.tools.nsc.typechecker.Namers$Namer$$anon$0.complete(Namers.scala:310)
	at scala.tools.nsc.symtab.Symbols$Symbol.info(Symbols.scala:346)
	at scala.tools.nsc.symtab.Symbols$Symbol.tpe(Symbols.scala:322)
	at scala.tools.nsc.symtab.Types$Type.memberType(Types.scala:203)
	at scala.tools.nsc.symtab.Types$Type.findMember(Types.scala:415)
	at scala.tools.nsc.symtab.Types$Type.implicitMembers(Types.scala:169)
	at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:310)
	at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:319)
	at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:318)
	at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:318)
	at scala.tools.nsc.typechecker.Typers$Typer.inferImplicit(Typers.scala:1960)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$inferView(Typers.scala:66\
)
	at scala.tools.nsc.typechecker.Typers$Typer.inferView(Typers.scala:75)
	at scala.tools.nsc.typechecker.Typers$Typer.adaptToMember(Typers.scala:513)
	at scala.tools.nsc.typechecker.Typers$Typer.adaptToName(Typers.scala:522)
	at scala.tools.nsc.typechecker.Typers$Typer.typedSelect$0(Typers.scala:1298)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1694)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1763)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1790)
	at scala.tools.nsc.typechecker.Typers$Typer.computeType(Typers.scala:1823)
	at scala.tools.nsc.typechecker.Namers$Namer.scala$tools$nsc$typechecker$Namers$Namer$$typeSig(Namers.scala:497)\

	at scala.tools.nsc.typechecker.Namers$Namer$$anon$3.complete(Namers.scala:326)
	at scala.tools.nsc.symtab.Symbols$Symbol.info(Symbols.scala:346)
	at scala.tools.nsc.symtab.Symbols$Symbol.tpe(Symbols.scala:322)
	at scala.tools.nsc.ast.Trees$class.DefDef(Trees.scala:269)
	at scala.tools.nsc.Global.DefDef(Global.scala:32)
	at scala.tools.nsc.typechecker.Typers$Typer.addGetterSetter(Typers.scala:661)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$22.apply(Typers.scala:708)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$22.apply(Typers.scala:708)
	at scala.List.flatMap(List.scala:920)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:708)
	at scala.tools.nsc.typechecker.Typers$Typer.typedClassDef(Typers.scala:636)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1437)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1763)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1790)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$46.apply(Typers.scala:1003)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$46.apply(Typers.scala:993)
	at scala.List$.loop$0(List.scala:232)
	at scala.List$.mapConserve(List.scala:249)
	at scala.List$.loop$0(List.scala:236)
	at scala.List$.mapConserve(List.scala:249)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:993)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1433)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1763)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1790)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$1.apply(Analyzer.scala:38)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:220)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$1.apply(Global.scala:209)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$1.apply(Global.scala:209)
	at scala.Iterator$class.foreach(Iterator.scala:304)
	at scala.collection.mutable.ListBuffer$$anon$0.foreach(ListBuffer.scala:216)
	at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:209)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:471)
	at scala.tools.nsc.Global$Run.compile(Global.scala:535)
	at scala.tools.nsc.Main$.process(Main.scala:76)
	at scala.tools.nsc.Main$.main(Main.scala:98)
	at scala.tools.nsc.Main.main(Main.scala)
sean-mcdirmids-computer:~/workspace/test10/src mcdirmid$ 
what expected
test/B.scala:12 error: overloaded method coerce needs result type
  implicit def coerce(p : ParentImpl) = p.self;
                                         ^
one error found
[back to overview]
Changes of this bug report
Sean  edited on  2006-08-22 14:05:40.0
Martin  edited on  2006-08-22 16:43:04.0
One now gets:
bug712.scala:10 error: value self is not a member of B.this.ParentImpl
  implicit def coerce(p : ParentImpl) = p.self;
                                         ^
one error found
Makes sense. We cannot use the coerce method to do implicit conversions in its own body.