This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Trying to use TreeDSL, but get assertion failure

4 replies
Mirko Stocker
Joined: 2009-09-10,
User offline. Last seen 45 weeks 6 days ago.

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

Kevin Wright
Joined: 2009-06-09,
User offline. Last seen 49 weeks 3 days ago.
Re: Trying to use TreeDSL, but get assertion failure
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.



On Wed, Dec 2, 2009 at 1:26 PM, Mirko Stocker <me [at] misto [dot] ch> wrote:
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.<init>(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$.<init>(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



Mirko Stocker
Joined: 2009-09-10,
User offline. Last seen 45 weeks 6 days ago.
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

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
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.)

Mirko Stocker
Joined: 2009-09-10,
User offline. Last seen 45 weeks 6 days ago.
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.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland