HaxeFoundation / HaxeFoundation/haxe

`@:using` not working on types inferred from inline & cast-only functions

Open
#10,693 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Haxe v4.2.5 - nightly 651ecf3

Sometimes I'd like to have inline functions just for type cast (like `castMyType()` in the code below),
rather than typing explicitly (like `var value:MyType = {num: 0}` or `({num: 0} : MyType)` ).

However it seems that `@:using` does not work with such kind of code under some conditions.
And it depends on the target which functions are considered "cast only".

Code expected to compile but actually not:

```haxe
// ---- Main.hx ----

function main() {
final value = castMyType({num: 0}); // vshaxe says value is MyType. No error if explicit type hint
value.doSomething(); // Compiler error on static targets: "{ num : Int } has no field doSomething"
}

// No error if inline removed
inline function castMyType(x:MyType):MyType {
// No error if some other code here
return x;
}

@:using(Main.MyTypeTools) // No error if traditional `using` instead
typedef MyType = {
final num:Int; // Changing final to var raises the same error even on dynamic targets
}

class MyTypeTools {
public static function doSomething(x:MyType)
trace("hello");
}
```

(I doubt this is a duplicate of another issue, though I didn't find a similar one)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.