HaxeFoundation / HaxeFoundation/HaxeManual
Constant page does not describe 'static inline var' as creating a constant.
- Dominant language
- Haxe
- Stars
- 225
- Forks
- 156
- Avg merge
- 5h 16m
- Merged PRs (30d)
- 1
Description
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):
```Haxe
class Test {
static inline var myConstant : Int = 4 + 3; // Expression!
static inline var myStr = "Something";
static inline var myInt = Std.int(1.2);
static inline var myComposite = "1" + "2";
@:pure
public static function concat(a:String, b:String) : String {
return a + b;
}
public static function test(param : Int = myConstant) {return param;}
public static function test2(param : Int = myInt) {return param;}
public static function test3(param : String = myStr) {return param;}
//public static function test4(param : String = myComposite) {} // Only this one causes an error.
static function main() {
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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the constants page at https://haxe.org/manual/expression-constants.html and the supplied Haxe examples, then verify which static inline var expressions are accepted for default arguments. Update the constants and default-parameter documentation to describe the valid expressions and correct the statement that all constants are literals.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100