Aladdin - Scala Bugtracking
[#536] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Lex Martin fixed 2006-02-23 12:56:14.0
subject inferring parameter type for non-default constructor
code
// Tests instantiating a type parameter when a non-default
// constructor is used.


class Atom[T](b: Boolean) {
  def this(s: T) = this(true)
}


object AtomTest {
  val x = new Atom("hello")
}
what happened
Exception in thread "main" java.lang.Error: T in class Atom cannot be instantiated from Atom[T]
        at scala.tools.nsc.symtab.Types$AsSeenFromMap.throwError$0(Types.scala:1222)
        at scala.tools.nsc.symtab.Types$AsSeenFromMap.instParam$0(Types.scala:1225)
        at scala.tools.nsc.symtab.Types$AsSeenFromMap.toInstance$0(Types.scala:1233)
        at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:1239)
        at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:1206)
        at scala.List$.loop$0(List.scala:241)
        at scala.List$.mapConserve(List.scala:258)
        at scala.tools.nsc.symtab.Types$TypeMap$class.mapOver(Types.scala:1130)
        at scala.tools.nsc.symtab.Types$AsSeenFromMap.mapOver(Types.scala:1206)
        at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:1241)
        at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:1206)
        at scala.tools.nsc.symtab.Types$TypeMap$class.mapOver(Types.scala:1163)
        at scala.tools.nsc.symtab.Types$AsSeenFromMap.mapOver(Types.scala:1206)
        at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:1241)
        at scala.tools.nsc.symtab.Types$Type.asSeenFrom(Types.scala:186)
        at scala.tools.nsc.symtab.Types$Type.memberType(Types.scala:195)
        at scala.tools.nsc.typechecker.Infer$Inferencer.checkAccessible(Infer.scala:249)
        at scala.tools.nsc.typechecker.Typers$Typer.typedSelect$0(Typers.scala:1034)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1410)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1473)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1344)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1473)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1497)
        at scala.tools.nsc.typechecker.Typers$Typer.computeType(Typers.scala:1528)
        at scala.tools.nsc.typechecker.Namers$Namer.liftedTry0$0(Namers.scala:484)
        at scala.tools.nsc.typechecker.Namers$Namer.scala$tools$nsc$typechecker$Namers$Namer$$typeSig(Namers.sca\
la:461)
        at scala.tools.nsc.typechecker.Namers$Namer$$anon$3.complete(Namers.scala:325)
        at scala.tools.nsc.symtab.Symbols$Symbol.info(Symbols.scala:342)
        at scala.tools.nsc.symtab.Symbols$Symbol.tpe(Symbols.scala:318)
        at scala.tools.nsc.ast.Trees$class.DefDef(Trees.scala:264)
        at scala.tools.nsc.Global.DefDef(Global.scala:30)
        at scala.tools.nsc.typechecker.Typers$Typer.addGetterSetter(Typers.scala:614)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$20.apply(Typers.scala:652)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$20.apply(Typers.scala:652)
        at scala.List.flatMap(List.scala:930)
        at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:652)
        at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:600)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1154)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1473)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1497)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$41.apply(Typers.scala:905)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$41.apply(Typers.scala:895)
        at scala.List$.loop$0(List.scala:241)
        at scala.List$.mapConserve(List.scala:258)
        at scala.List$.loop$0(List.scala:245)
        at scala.List$.mapConserve(List.scala:258)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:895)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1147)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1473)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:1497)
        at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$1.apply(Analyzer.scala:39)
        at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:188)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$1.apply(Global.scala:177)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$1.apply(Global.scala:177)
        at scala.Iterator$class.foreach(Iterator.scala:262)
        at scala.collection.mutable.ListBuffer$$anon$0.foreach(ListBuffer.scala:218)
        at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:177)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:402)
        at scala.tools.nsc.Global$Run.compile(Global.scala:460)
        at scala.tools.nsc.Main$.process(Main.scala:57)
        at scala.tools.nsc.Main$.main(Main.scala:69)
        at scala.tools.nsc.Main.main(Main.scala)
what expected It should either infer the parameter type, or produce a nice error message. Since it *does* infer the type when using the default constructor, maybe it is easy to infer the type in this case, too?
[back to overview]
Changes of this bug report
Lex  edited on  2006-02-23 12:56:41.0
Martin  edited on  2006-02-25 19:10:11.0