Skip to content

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

Description

@T1mL3arn

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

No error if class is stored in a typed variable.

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

import haxe.ds.Either;

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

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

		// doesnt work
		test(Foo);

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

	static function test(val:OneOf<String, Class<Any>>) {}
}

class Foo {}

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

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

 13 |   test(Foo);
    |        ^^^
    | Class<Foo> should be OneOf<String, Class<Any>>
    | For function argument 'val'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions