Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[abstracts] unification of nested abstracts in type parameters and structure fields #9721

Closed
vonagam opened this issue Jul 16, 2020 · 1 comment · Fixed by #9723
Closed

Comments

@vonagam
Copy link
Member

vonagam commented Jul 16, 2020

Example:

import haxe.ds.ReadOnlyArray as MyArray;

abstract Foo<T>(T) from T to T {}
abstract Bar<T>(Foo<T>) from T to T {}

class Main {
  public static function main() {
    ((null: {x: Array<Array<Int>>}): {x: MyArray<Array<Int>>}); // works
    ((null: {x: Array<Array<Int>>}): {x: Array<MyArray<Int>>}); // works
    ((null: {x: Array<Array<Int>>}): {x: MyArray<MyArray<Int>>}); // fails - 1

    ((null: {x: Int}): {x: Foo<Int>}); // fails - 2
    ((null: {x: String}): {x: Foo<String>}); // works
    ((null: {x: String}): {x: Bar<String>}); // fails - 3
  }
}

Same issues with type params (can be checked by replacing {x: Type} with Array<Type> in the example) because both use unify_with_variance.

Fist fail happens because unify_with_variance stops going deeper the moment it encounters an abstract and uses equality check for comparison of direct casts after that and as Array<Array<Int>> and Array<MyArray<Int>> are not equal, the unification fails.

Second fail is a mystery for me right now.

Third one happens because underlying type is not resolved deeper - Foo<String> is not equal to String.

@vonagam
Copy link
Member Author

vonagam commented Jul 17, 2020

Another problem:

abstract MyInt(Int) from Int to Int to Float {}

class Main {
  public static function main() {
    ((null: Array<Int>): Array<Float>); // fails
    ((null: Array<MyInt>): Array<Float>); // works when shouldn't...
  }
}

This one because only if both abstracts are core type underlying type is checked, otherwise the check is skipped.

Also, second fail in first example happens because in abstract-abstract apply_params is not called, unlike abstract-t or t-abstract.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant