#1352 Dsl variable resolving

vkuzkokov Mon 6 Dec 2010

Suppose I want $x in DSL to be interpreted as variable x from local context. Apparently, it's not easy. LocalVarExpr is initialized with binding and UnknownVarExpr will get obscure compile-time error when dsl is used.

diff -r d8c434395bae src/compiler/fan/steps/ResolveExpr.fan
--- a/src/compiler/fan/steps/ResolveExpr.fan	Thu Dec 02 15:28:23 2010 -0500
+++ b/src/compiler/fan/steps/ResolveExpr.fan	Sat Dec 04 23:14:43 2010 +0600
@@ -739,6 +739,7 @@
     {
       result := plugin.compile(expr)
       if (result === expr) return result
+      result.walk(this)
       return visitExpr(result)
     }
     catch (CompilerErr e)

With proposed patch UnknownVarExpr generated in DSL will work as expected (be resolved to local, field or method call with no args).

brian Mon 6 Dec 2010

Yeah that makes sense. Although I don't think your patch is quite right - you shouldn't have both a walk and visitExpr because you will end up doing potentially two replacements (walk already does a visitExpr). I pushed this changeset which should do the trick. If not let me know.

Login or Signup to reply.