- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Confused about the "typer phase"; Why all ClassDef.tpe == <notype>?
Sat, 2011-10-22, 14:34
If my PluginComponent has:
val runsAfter = List[String]("typer")
and my TypingTransformer has:
override def transform(tree: Tree): Tree = {
super.transform(tree) match {
case cd : ClassDef =>
log("Type of "+cd+" is "+cd.tpe)
cd
case x => x
}
}
What I see is that all ClassDef have a .tpe of Is that not
the job of the typer phase to give a type to everything, and should I
not therefore have a real type when I call .tpe inside a
PluginComponent that runs after the typer phase? Even calling
something like "typer.typed(cd)" makes no difference.
I am trying to use the following code, and it fails because the
*original.tpe* is :
val original: ClassDef = ... // Some trait
val owner = original.symbol.owner
val name = newTypeName("foo")
val myNewClass = owner.newClass(owner.pos, name).setFlag(SYNTHETIC)
val parents = List(definitions.ObjectClass.tpe, *original.tpe*)
myNewClass.setInfo(ClassInfoType(parents, new Scope, myNewClass))
Also, is there some link that not simply list the different phases,
but actually explains *what* each of them does in more detail than
what scalac says?
scalac -Xshow-phases returns:
...
typer 4 the meat and potatoes: type the trees
...
But "type the trees" apparently does not equate "make sure all things
get a type", so I find this description somewhat misleading...
Sat, 2011-10-22, 22:07
#2
Re: Confused about the "typer phase"; Why all ClassDef.tpe == <
On Sat, Oct 22, 2011 at 6:34 AM, monster wrote:
> But "type the trees" apparently does not equate "make sure all things
> get a type", so I find this description somewhat misleading...
NoType is a type. The absence of a type is represented by null.
let's take this to scala-internals
On Sat, Oct 22, 2011 at 3:34 PM, monster <skunkiferous@googlemail.com> wrote:
that's because typedClassDef does not give the ClassDef a type(see https://github.com/adriaanm/scala-dev/blob/master/src/compiler/scala/tools/nsc/typechecker/Typers.scala#L1338)
the info you're looking for is in the symbol of the classdef tree val parents = List(definitions.ObjectClass.tpe, original.symbol.tpe) // this should work there's Miguel's compiler corner: http://lamp.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/
just the other day I hacked something that creates a new class (it's just a first cut -- known to be a bit buggy)for what it's worth, here's the relevant commit: https://github.com/adriaanm/scala-dev/commit/c67f74f019c21d2b6832a30be7609c48a9664472
cheersadriaan