erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.69k stars 55 forks source link

Cannot compare mutable container (array, set, etc.) and immutable containers #193

Closed mtshiba closed 1 year ago

mtshiba commented 2 years ago

Reproducible code

i = !{1, 3}
i.add! 3
print! i
assert i == {1, 3}

a = ![1, 3]
a.push! 3
print! a
print! a == [1, 3, 3]

Expected behavior Passed.

Result

Error[#0595]: File examples/set_b.er, line 4, in <module>
4│ assert i == {1, 3}
          ^^^^^^^^^^^
TypeError: Set({1, 3, }, 2) or Set!(?T(:> {3, }, <: {3, 1, }), !2) does not implement Eq(Set({1, 3, }, 2) or Set!(?T(:> {3, }, <: {3, 1, }), !2))
Error[#0595]: File examples/set_b.er, line 9, in <module>
9│ print! a == [1, 3, 3]
          ^^^^^^^^^^^^^^
TypeError: Array({3, 1, }, 3) or Array!(?T(:> {3, }, <: {3, 1, }), !3) does not implement Eq(Array({3, 1, }, 3) or Array!(?T(:> {3, }, <: {3, 1, }), !3))
mtshiba commented 2 years ago

This code should also be passed.

j: {Int; 2} = !{1, 2}

but:

Error[#0052]: File <stdin>, line 1, in <module>
1│ j: {Int; 2} = !{1, 2}
   ^
TypeError: the type of j is mismatched:
expected:  Set(Int, Nat(2))
but found: Set!((?T(<: {Nat(2), Nat(1), }(cyclicity: Not))[0]), !Nat(2))

It seems that Set! is not recognized as a subtype of Set.