- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Trying to use TreeDSL, but get assertion failure
Wed, 2009-12-02, 14:24
Hello
For my refactoring project, I need to create Trees, and I was delighted when i
discovered the TreeDSL. Unfortunately, I can't get it to work. For example,
I'm trying I'm trying to create a literal like this:
object X extends TreeDSL {
val settings = new Settings( msg => () )
val global = new Global(settings, new ConsoleReporter(settings))
def main(args : Array[String]) : Unit = {
val l = CODE.LIT("a")
}
}
But this fails:
Exception in thread "main" java.lang.AssertionError: assertion failed
at scala.Predef$.assert(Predef.scala:89)
at scala.tools.nsc.symtab.Symbols$TypeHistory.(Symbols.scala:2063)
at scala.tools.nsc.symtab.Symbols$Symbol.setInfo(Symbols.scala:783)
at scala.tools.nsc.symtab.Symbols$TypeSymbol.setInfo(Symbols.scala:1845)
at
scala.tools.nsc.symtab.Definitions$definitions$.RootClass(Definitions.scala:37)
at
scala.tools.nsc.symtab.Definitions$definitions$.getModuleOrClass(Definitions.scala:485)
at
scala.tools.nsc.symtab.Definitions$definitions$.getModule(Definitions.scala:444)
at
scala.tools.nsc.symtab.Definitions$definitions$.ScalaPackage(Definitions.scala:43)
at scala.tools.nsc.ast.TreeGen.scalaDot(TreeGen.scala:26)
at scala.tools.nsc.ast.TreeDSL$CODE$.(TreeDSL.scala:211)
at scala.tools.refactoring.scripts.X$.CODE(Parts2.scala:15)
at scala.tools.refactoring.scripts.X$.main(Parts2.scala:22)
at scala.tools.refactoring.scripts.X.main(Parts2.scala)
Now, I guess I'm either not using the compiler correctly (although
instantiating it like this works fine for my other usages) or I'm abusing the
TreeDSL somehow.. any insights?
Thanks a lot
Mirko
Wed, 2009-12-02, 15:27
#2
Re: Trying to use TreeDSL, but get assertion failure
On Wednesday 02 December 2009 14:56:06 Kevin Wright wrote:
> It's failing to lookup the package "scala" when trying to get the symbol
> for "scala.Some" in the TreeDSL constructor.
> This in turn is caused by the lack of type history (Symbols.scala, lines
> 783 and 2063)
>
> My guess would be that Global isn't 100% ready for action after being
> constructed, and needs a bit extra initialization work.
Hm, ok, that makes sense. So something like this [1] is needed? Unfortunaly,
that doesn't solve it for me, still get the same failure.
Thanks!
Mirko
[1] http://speaking-my-language.blogspot.com/2009/11/embedded-scala-
interpreter.html
Wed, 2009-12-02, 15:37
#3
Re: Trying to use TreeDSL, but get assertion failure
On Wed, Dec 02, 2009 at 01:56:06PM +0000, Kevin Wright wrote:
> My guess would be that Global isn't 100% ready for action after being
> constructed, and needs a bit extra initialization work.
Correct, it's because definitions.init hasn't been called.
Put this line after val global:
new global.Run
and it will work. (Not proposing that as the long term answer -- you
might also try calling init directly. Someday this will be cleaner.)
Wed, 2009-12-02, 15:47
#4
Re: Trying to use TreeDSL, but get assertion failure
On Wednesday 02 December 2009 15:20:50 Paul Phillips wrote:
> Correct, it's because definitions.init hasn't been called.
>
> Put this line after val global:
>
> new global.Run
>
> and it will work. (Not proposing that as the long term answer -- you
> might also try calling init directly. Someday this will be cleaner.)
That's great! Thanks a lot.
My guess would be that Global isn't 100% ready for action after being constructed, and needs a bit extra initialization work.
On Wed, Dec 2, 2009 at 1:26 PM, Mirko Stocker <me [at] misto [dot] ch> wrote: