HaxeFoundation / HaxeFoundation/haxe

`A should be B` when passing a bare `Class` reference to an abstract enum wrapper

Open
#12,929 2 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

When passing a bare class reference identifier (e.g., `Foo`) directly into a function parameter typed as an abstract enum wrapper `OneOf>` `@:from` should return `Right`. But instead compiler throws `Class should be OneOf>`.

No error if class is stored in a typed variable.

https://try.haxe.org/#E9de3B35

```haxe
import haxe.ds.Either;

class Test {
static function main() {
// works
test('hi');

// works
var c:Class = Foo;
test(c);

// doesnt work
test(Foo);

// works
test(cast Right(Foo));
}

static function test(val:OneOf>) {}
}

class Foo {}

abstract OneOf(Either) from Either to Either {
@:from inline static function fromA(a:A):OneOf {
return Left(a);
}

@:from inline static function fromB(b:B):OneOf {
return Right(b);
}
}
```
```
[ERROR] Test.hx:13: characters 8-11

13 | test(Foo);
| ^^^
| Class should be OneOf>
| For function argument 'val'
```

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.