What causes Haxe error "Invalid build parameters"

50 Views Asked by At

When I try to compile my project, Haxe gives a single line of output:

> haxe build.hxml
MyClass.hx:3: character 1 : Invalid build parameters

The line number points to a class in my code that looks fine...

class MyClass implements MyInterface {

What is the problem? Google has no hits for this error message.

1

There are 1 best solutions below

0
Jeff Ward On

Explanation:

While the compiler error message confusingly points to the MyClass.hx file, the error is referring to the @:autoBuild specification (docs), which is on the interface definition. There is likely a syntax error with this specification.

An example of correct syntax for this metadata is:

@:autoBuild( pkg.MyMacro.build_my_interface() )
interface MyInterface { }

This assumes that the MyMacro class is in the pkg package and has the specified build macro of this form:

public static macro function build_my_interface():Array<Field>
{
  var fields = Context.getBuildFields();
  // modify fields / etc
  return fields;
}

Read more about build macros here.

Possible Syntax Errors:

There are a few potential problems that may cause Invalid build parameters:

  • The macro class is either not imported or not specified with the full package syntax.
  • The build macro function is missing from the MyMacro class, or misspelled.
  • You might have forgotten to call the build macro function (missing () at the end.)
  • Note that the complete function call goes inside @:autoBuild( ) (including optional function arguments) so check for mismatched parentheses.