Skip to content

For bodyless abstract ops, allow unification between underlying type and abstract return type #2409

Closed
@Herschel

Description

@Herschel

Thise code fails with The result of this operation (Int) is not compatible with declared return type Foo

abstract Foo(Int) {
    public function new(x:Int) this = x;
    @:op(A+B) public static function add(a:Foo, b:Foo):Foo;
}

class Main {
    public static function main() {
        var f:Foo = new Foo(1);
        f+f;
    }
}

Adding from Int to the abstract allows the unification with the return type. However, I may not want to allow that unification in general. This forces me to painfully supply bodies for all of the operators, e.g. return new Foo((cast a) + (cast b)).

It'd be nice if the compiler allowed the unification between the abstract type and underlying type in the case of bodyless operators.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions