Skip to content

Commit

Permalink
Fixed subtyping bug, if supertype is an Intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
christofsteel committed Oct 25, 2023
1 parent e8c8aa3 commit c7b2c8b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bcls/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def _check_subtype_rec(self, subtypes: deque[Type], supertype: Type) -> bool:
and self._check_subtype_rec(casted_r, r2)
)
case Intersection(l, r):
return self._check_subtype_rec(subtypes, l) and self._check_subtype_rec(
subtypes, r
)
return self._check_subtype_rec(
subtypes.copy(), l
) and self._check_subtype_rec(subtypes, r)
case _:
raise TypeError(f"Unsupported type in check_subtype: {supertype}")

Expand Down
28 changes: 28 additions & 0 deletions tests/test_subtype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import logging
import unittest
from bcls import Constructor
from bcls.subtypes import Subtypes
from bcls.types import Intersection


class TestSubtype(unittest.TestCase):
logger = logging.getLogger(__name__)
logging.basicConfig(
format="%(module)s %(levelname)s: %(message)s",
# level=logging.INFO,
)

def test_constructor_refl(self) -> None:
a = Constructor("A")
subtypes = Subtypes({})
self.assertTrue(subtypes.check_subtype(a, a))

def test_idempotence_right(self) -> None:
a = Constructor("A")

subtypes = Subtypes({})
self.assertTrue(subtypes.check_subtype(a, Intersection(a, a)))


if __name__ == "__main__":
unittest.main()

0 comments on commit c7b2c8b

Please sign in to comment.