Skip to content

Commit

Permalink
map equality
Browse files Browse the repository at this point in the history
  • Loading branch information
pshirshov committed Aug 24, 2023
1 parent 7db8978 commit 906ecc3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ object CSDefnTranslator {
q"Equals($ref, other.$ref)"
case ComparatorType.SeqEquals =>
q"$ref.SequenceEqual(other.$ref)"
case ComparatorType.SetEquals =>
q"$ref.SetEquals(other.$ref)"
case ComparatorType.MapEquals =>
val oref = q"other.$ref"
q"($ref.Count == $oref.Count && !$ref.Keys.Any(key => !$oref.Keys.Contains(key)) && !$ref.Keys.Any(key => $oref[key] != $ref[key]))"
}
}

Expand Down
28 changes: 17 additions & 11 deletions src/main/scala/io/septimalmind/baboon/typer/model/Typedef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ object TypeId {
case object ObjectEquals extends ComparatorType
case object OptionEquals extends ComparatorType
case object SeqEquals extends ComparatorType
case object SetEquals extends ComparatorType
case object MapEquals extends ComparatorType
}

def comparator(ref: TypeRef): ComparatorType = {
Expand All @@ -143,17 +145,21 @@ object TypeId {
ComparatorType.ObjectEquals
}
case c: TypeRef.Constructor =>
if (c.id == TypeId.Builtins.opt) {
comparator(c.args.head) match {
case ComparatorType.Direct => ComparatorType.Direct
case _ => ComparatorType.OptionEquals
}
} else if (TypeId.Builtins.iterableCollections
.toSet[TypeId]
.contains(c.id)) {
ComparatorType.SeqEquals
} else {
ComparatorType.ObjectEquals
c.id match {
case TypeId.Builtins.opt =>
comparator(c.args.head) match {
case ComparatorType.Direct => ComparatorType.Direct
case _ => ComparatorType.OptionEquals
}
case TypeId.Builtins.set =>
ComparatorType.SetEquals

case TypeId.Builtins.map =>
ComparatorType.MapEquals
case TypeId.Builtins.lst =>
ComparatorType.SeqEquals
case _ =>
ComparatorType.ObjectEquals
}
}
}
Expand Down

0 comments on commit 906ecc3

Please sign in to comment.