You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Constant expressions are required for default arguments in function parameters. The compiler allows variables declared as 'static inine var' and allowing some level of expression to be used in that position.
For example, the following code compiles, but you wouldn't know it from reading the manual page for either constants or default parameters (which only mentions that the default value must be a constant):
classTest {
staticinlinevarmyConstant:Int=4+3; // Expression!staticinlinevarmyStr="Something";
staticinlinevarmyInt=Std.int(1.2);
staticinlinevarmyComposite="1"+"2";
@:purepublicstaticfunctionconcat(a:String, b:String) :String {
returna+b;
}
publicstaticfunctiontest(param:Int=myConstant) {returnparam;}
publicstaticfunctiontest2(param:Int=myInt) {returnparam;}
publicstaticfunctiontest3(param:String=myStr) {returnparam;}
//public static function test4(param : String = myComposite) {} // Only this one causes an error.staticfunctionmain() {
trace(test());
trace(test2());
trace(test3());
//trace(test4());
}
}
Additionally, the manual page contains the text: "All constants are literals, except for argument-less enum constructors:", which is incorrect (because an expression is not defined as a literal, even though it is allowed).
Please also document what expressions are considered valid when creating a constant.
The text was updated successfully, but these errors were encountered:
According to @Simn: Some functions are optimized in the compiler if they
have static arguments: Type.enumIndex, String.fromCharCode,
Std.string, Std.int, Math.ceil, Math.floor, Std.is.
Regarding page: https://haxe.org/manual/expression-constants.html
Constant expressions are required for default arguments in function parameters. The compiler allows variables declared as 'static inine var' and allowing some level of expression to be used in that position.
For example, the following code compiles, but you wouldn't know it from reading the manual page for either constants or default parameters (which only mentions that the default value must be a constant):
Additionally, the manual page contains the text: "All constants are literals, except for argument-less enum constructors:", which is incorrect (because an expression is not defined as a literal, even though it is allowed).
Please also document what expressions are considered valid when creating a constant.
The text was updated successfully, but these errors were encountered: