AndreVanDelft / scala

The SubScript extension to the Scala programming language
http://www.subscript-lang.org/
12 stars 1 forks source link

Launch anchor and launch nodes are treated as `Any` inside annotations #25

Closed anatoliykmetyuk closed 10 years ago

anatoliykmetyuk commented 10 years ago

Consider following script:

live = @{}: (** {. .} **)

In AST view, it will look like follows:

<caseaccessor> def _live(): subscript.DSL.Script[scala.Unit] = subscript.DSL._script(this, scala.Symbol("live"))(subscript.DSL._at(((there: Any) => ()))(subscript.DSL._launch_anchor(subscript.DSL._eventhandling(((here: subscript.vm.N_code_eventhandling) => ())))))

Now instead of

subscript.DSL._at(((there: Any) => ()))

we should have

subscript.DSL._at(((there: N_launch_anchor) => ()))

In case of other nodes, the type of there is set correctly, so the issue is only with N_launch_anchor and N_launch (which behaves identically to N_launch_anchor in this case).

anatoliykmetyuk commented 10 years ago

One thing to consider is how nodes are defined in DSL. Launch anchor is defined as follows:

  def _launch_anchor = (child0  : TemplateChildNode ) => T_launch_anchor(child0)

as opposed to other nodes defined as follows

  def _normal             (cf: => (N_code_normal             =>Unit)) = T_code_normal            (() => cf)

That is, launch anchor outputs a function, whereas other nodes output templates.

AndreVanDelft commented 10 years ago

You were right! This was the problematic code at line 1540 of Parsers.scala:

    def vmNodeOf (tree: Tree): Tree   = tree match { // for @ nodes; these need to know the node type of their operand; very messy...
      case (Apply(fun, Function(List(ValDef(_,_, nodeType,_)),block)::_)) => nodeType
      case _ => Ident(any_TypeName)
    }

I added this nasty line:

      case Apply(Select(_, fun_name), _) => vmNodeFor(LPAREN_ASTERISK2) // brutally assuming that fun_name is _launch_anchor

It works; we will have to move all this processing code anyway out of Parser.scala anyway, so a little polution is no big deal.