HaxeFoundation / HaxeFoundation/haxe
Abstract types declared as inline return a compiler error with -debug mode on
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
Hi there,
I've created an abstract Float type to help with implicit casts between Float and Int (akin to how AS3 does it):
```haxe
package;
abstract AbsFloat(Float) from Float to Float {
public inline function new(i:Float) {
this = i;
}
@:to
public inline function toInt() {
return Std.int(this);
}
@:to
public inline function toFloat() {
return this;
}
@:from
static public inline function fromFloat(f:Float) {
return new AbsFloat(f);
}
@:from
static public inline function fromInt(i:Int) {
return new AbsFloat(i);
}
}
class Test
{
public static inline var k : AbsFloat = 1;
static function main()
{
var i2:Int = k;
trace("Haxe is great! " + i2);
}
}
```
I'm creating a field `public static inline var k : AbsFloat = 1;`, notably initializing it to an `Int` value rather than a `Float`. The Haxe compiler should be able to handle that case afaik.
When I compile this code _without -debug_, I get no errors:
`haxe -js Main Main.hx`
Yay.
However, when I add `-debug`, I get the following error:
```
haxe -js Main Main.hx -debug
Main.hx:31: characters 2-44 : Inline variable initialization must be a constant value
```
I get the same behaviour with Haxe 3.4.7 and 4.0.5.
Contributor guide
Assessment
This issue has not been assessed yet.