Skip to content

Commit

Permalink
Merge branch 'master' into oscar/20240107_base_2_8_16
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek authored Jan 7, 2024
2 parents 62acd3d + 0ac041d commit 1c2799f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
11 changes: 9 additions & 2 deletions core/src/main/scala/org/bykn/bosatsu/pattern/SeqPattern.scala
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,16 @@ object SeqPattern {
if (p1.matchesEmpty) p2 :: Nil else Nil
case (_, Cat(Wildcard, _)) if p2.matchesAny =>
// matches anything
p1 :: Nil
val res =
if (p1.matchesAny) {
// both match any, return a normalized value
Wild
}
else p1

res :: Nil
case (Cat(Wildcard, _), p2) if p1.matchesAny =>
// matches anything
// p1 matches anything, but p2 doesn't
p2 :: Nil
case (Cat(Wildcard, t1@Cat(Wildcard, _)), _) =>
// unnormalized
Expand Down
16 changes: 11 additions & 5 deletions core/src/test/scala/org/bykn/bosatsu/pattern/SeqPatternTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ abstract class SeqPatternLaws[E, I, S, R] extends AnyFunSuite {
assert(int1 == List(Cat(AnyElem, Cat(Wildcard, Empty))))
}

test("[*] n [*, *] commutes") {
val p1 = Cat(Wildcard, Empty)
val p2 = Cat(Wildcard, p1)
val int1 = setOps.intersection(p1, p2)
val int2 = setOps.intersection(p2, p1)
assert(int1 == int2)
}

test("x n y == y n x") {
forAll(genPattern, genPattern) { (x: Pattern, y: Pattern) =>
val i1 = setOps.intersection(x, y)
Expand All @@ -367,18 +375,16 @@ abstract class SeqPatternLaws[E, I, S, R] extends AnyFunSuite {
}
}

/*
test("if x - y is empty, (x + z) - (y + z) is empty") {
forAll { (x0: Pattern, y0: Pattern, z0: Pattern) =>
forAll(genPattern, genPattern, genPattern) { (x0: Pattern, y0: Pattern, z0: Pattern) =>
val x = Pattern.fromList(x0.toList.take(3))
val y = Pattern.fromList(y0.toList.take(3))
val z = Pattern.fromList(z0.toList.take(3))
if (x.difference(y).isEmpty) {
assert((x + z).difference(y + z) == Nil)
if (setOps.difference(x, y).isEmpty) {
assert(setOps.differenceAll(x :: z :: Nil, y :: z :: Nil) == Nil)
}
}
}
*/
}

class BoolSeqPatternTest extends SeqPatternLaws[Set[Boolean], Boolean, List[Boolean], Unit] {
Expand Down

0 comments on commit 1c2799f

Please sign in to comment.