Skip to content

abstract casting #3494

Closed
Closed
@andyli

Description

@andyli

While trying to write a more advanced EitherType, I faced the following issue:

abstract E2<T1,T2>(Dynamic)
from T1 from T2 from E2<T2,T1>
to T1 to T2 to E2<T2,T1>
{}

class Test {
    function main():Void {
        var v1:E2<Int,String> = 1;
        var v2:E2<String,Int> = 2;
        v1 = v2; //E2<String, Int> should be E2<Int, String>
    }
}

Try to workaround, faced another issue:

abstract E2<T1,T2>(Dynamic)
from T1 from T2
to T1 to T2
{
    // note that it compiles fine if not inline
    @:from inline static function _from2<_T1:E2<T1,T2>, _T2:E2<T1,T2>>(e:E2<_T1,_T2>):E2<T1,T2> {
        return untyped e;
    }
}
class Test {
    function main():Void {
        var v1:E2<Int,String> = 1;
        var v2:E2<String,Int> = 2;
        v1 = v2; //e : E2<Unknown<0>, Unknown<1>> -> E2<E2.T1, E2.T2> should be E2<String, Int> -> E2<Int, String>
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions