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

Unions of 3 or more types involving modules are not commutative #10788

Open
HertzDevil opened this issue Jun 5, 2021 · 0 comments
Open

Unions of 3 or more types involving modules are not commutative #10788

HertzDevil opened this issue Jun 5, 2021 · 0 comments

Comments

@HertzDevil
Copy link
Contributor

HertzDevil commented Jun 5, 2021

#10527 made Union(T, U) and Union(U, T) equivalent only if neither T nor U is itself an (irreducible) union type, as the outer type merge algorithm (Crystal::Program#type_combine) was untouched. Certain union operations still fail to be commutative and associative if unions and modules are involved:

module A; end
class B; include A; end
class C; include A; end

(A | B) | C # => A
(A | C) | B # => A
(B | A) | C # => A
(B | C) | A # => (A | C)
(C | A) | B # => A
(C | B) | A # => (A | C)

A | (B | C) # => A
A | (C | B) # => A
B | (A | C) # => A
B | (C | A) # => A
C | (A | B) # => A
C | (B | A) # => A

Union(A, B, C) # => A
Union(A, C, B) # => A
Union(B, A, C) # => A
Union(B, C, A) # => (A | C)
Union(C, A, B) # => A
Union(C, B, A) # => (A | B)

All of the above unions should produce A.

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

No branches or pull requests

2 participants