Macros break Lime Assets

Calling any macro function seems to break Lime Assets and Lime in general. Am I doing something wrong?

package main;

import haxe.macro.Expr;
import lime.Assets;
import lime.app.Application;

/**
 * ...
 * @author Simon
 */
class Main extends Application 
{

	public function new() 
	{
		super();
	}
	
	override public function exec():Int 
	{
		
		trace( add(1) );
		
		trace( Assets.getText( "assets/thing.txt" ) );
		
		return super.exec();
		
		
	}
	
	macro static function add(e:Expr) {
		return macro $e + $e;
	}
	
}

I get these errors

Building Macros
Running Pre-Build Command Line...
cmd: "C:\HaxeToolkit\haxe/haxelib" run lime build "project.xml" neko -release -Dfdb
C:/HaxeToolkit/haxe/lib/lime/2,9,1/lime/_backend/native/NativeWindow.hx:134: characters 15-38 : Unknown identifier : lime_window_get_display
C:/HaxeToolkit/haxe/lib/lime/2,9,1/lime/_backend/native/NativeWindow.hx:227: characters 20-41 : Unknown identifier : lime_window_get_width
C:/HaxeToolkit/haxe/lib/lime/2,9,1/lime/_backend/native/NativeWindow.hx:228: characters 21-43 : Unknown identifier : lime_window_get_height
C:/HaxeToolkit/haxe/lib/lime/2,9,1/lime/_backend/native/NativeWindow.hx:229: characters 16-33 : Unknown identifier : lime_window_get_x
C:/HaxeToolkit/haxe/lib/lime/2,9,1/lime/_backend/native/NativeWindow.hx:230: characters 16-33 : Unknown identifier : lime_window_get_y
C:/HaxeToolkit/haxe/lib/lime/2,9,1/lime/_backend/native/NativeRenderer.hx:122: characters 21-46 : Unknown identifier : lime_renderer_read_pixels
src/uk/co/mrsimonmorris/Main.hx:24: characters 9-23 : Class<lime.Assets> has no field getText
C:/HaxeToolkit/haxe/lib/lime/2,9,1/lime/app/Preloader.hx:25: characters 25-53 : Unknown<0> cannot be constructed
Build halted with errors.

If I comment out the macro call everything is fine. The macro is copied from the Haxe Manual. Any idea what’s going on here?

Macros do not play well with most imports. You can import things from the haxe.macro package, and you can use utility classes like StringTools, but importing from the lime package is asking for trouble.

Generally, the best way to handle macros is to put them in their own file, like so:

package main;

//Macro-friendly imports only.
import haxe.macro.Expr;

class MainMacros
{
    public static macro function add(e:Expr):Expr
    {
        return macro $e + $e;
    }
}

Then your main class can import whatever you like.