HaxeFoundation / HaxeFoundation/haxe

Can't cast to a @:generic type parameter

Open
#9,284 1 comment 3 reactions 0 assignees View on GitHub
feature-generic
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

> [this forum post](https://community.haxe.org/t/working-with-generics-entities-and-components/2331) got me thinking about this

This looks like it should work, since `C` is known at compile-time:

```haxe
@:generic function doCast(v:Any, c:Class):C {
return cast(v, C);
}
```

Currently, it fails with `Can't cast to a type parameter`, just like without `@:generic`.

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.