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

Wrong type parameter constraint checking error #4676

Closed
sledorze opened this issue Nov 26, 2015 · 2 comments
Closed

Wrong type parameter constraint checking error #4676

sledorze opened this issue Nov 26, 2015 · 2 comments

Comments

@sledorze
Copy link

typedef A = {
  var y : Int;
}

typedef B = {
  var x : Int;
}

class Test {


  static function foo<V, T : (V, A), U : (V, B)>(x : T) : Void {
  }

  static function main() {
    foo("toto");
  }
}

ouputs this error:

Build failure
Test.hx:16: characters 4-7 : Constraint check failure for foo.T
Test.hx:16: characters 4-7 : String should be B
Test.hx:16: characters 4-7 : String should be { x : Int }
Test.hx:16: characters 4-7 : String has no field x
Test.hx:16: characters 4-7 : Constraint check failure for foo.T
Test.hx:16: characters 4-7 : String should be A
Test.hx:16: characters 4-7 : String should be { y : Int }
Test.hx:16: characters 4-7 : String has no field y

Whereas 'String should be A' is correct, 'String should be B' is incorrect.

@Simn
Copy link
Member

Simn commented Nov 26, 2015

That looks like fun! Let's see if we can understand what happens:

Unification Assign To Result
Call String T T/String
Constraint check for T T/String V V/String
Constraint check for T T/String A "String should be A"
Constraint check for U U V/String U/String
Constraint check for U U/String B "String should be B"

This might be working as intended.

@sledorze
Copy link
Author

Mmmm, thanks for the explanation.
I was thinking that the compiler would infer U as a subtype of both V (string) and B (typedef); a kind of type union.
From your explanation, I understand that no ad'hoc subtype representation exist in the compiler.

Note: that maybe using 'String' for the example is misleading, the non shrinked version was involving only typedefs / anonymous

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

No branches or pull requests

2 participants