Visual Studio shows "the meaning of '<macro name>' does not allow this operation" in unstable manner, but the code compiles OK

36 views
Skip to first unread message

Vasily Kirichenko

unread,
Jun 16, 2015, 9:11:33 AM6/16/15
to nemer...@googlegroups.com
I'm trying to create a macro for generating new classes from string. The simplest thing I started is just generating an empty class with the given name:

macro BuildClassFromString(name)
       
Implementation.buildClassFromString(ImplicitCTX(), name)
 
module Implementation
   
public buildClassFromString(typer: Typer, typeName: PExpr) : PExpr
       
when (typer.IsMainPass)
            match
(typeName)
             
| <[ $(n: string) ]> =>
                 
DefineCTX(typer)
                 
def builder = typer.Env.Define (<[ decl:
                     
partial public class $(n: usesite) {
                     
}
                 
]>)
                  builder
.Compile()
             
| _ => Message.FatalError ("Type name should be a string literal")
       
<[]>


Usage:

BuildClassFromString("My")  
def _y = My()

It compiles OK and VS shows no errors, but if I change the usage code in any way (just add a space anywhere), the following error is shown:


"Error: AssertionException has occurred when expanding macro 'BuildClassFromString'"
"Error: the meaning of 'BuildClassFromString' does not allow this operation"

If I rebuild the usage project, the errors disappear until the file is changed again. 

So, the question: is it a bug in VS integration or my macro is not perfectly well written (I mean maybe `buildClassFromString` should return `void`)?
Reply all
Reply to author
Forward
0 new messages