basex icon indicating copy to clipboard operation
basex copied to clipboard

Replace AtomType.ENUM and SeqType.values by EnumType

Open GuntherRademacher opened this issue 1 year ago • 0 comments

Besides type inspection (#2300), there is at least one more problem with the current representation of enum types: MapType.keyType, as a Type, can currently only hold AtomType.ENUM and misses the values. Thus the following currently returns true, in lack of any values to be checked, but should return false:

{'b' cast as enum('b'): 1} instance of map(enum('a'), item())

Also, a multi-value enum is defined as a union of single-value enums, but we currently use different representations for either: multi-value enums have multiple values in one SeqType instance, but a ChoiceItemType may spread them over several instances. This can cause instance tests to fail, e.g. with a wrong result of false in this case:

fn($a as (enum('a')|enum('b'))) as item()* {$a} instance of fn(enum('a', 'b')) as item()*

These changes

  • remove AtomType.ENUM and SeqType.values.
  • convert EnumValues into an implementation of Type called EnumType.
  • combine consecutive EnumTypes before creating a ChoiceItemType. This solves the above mentioned problem with the function instance test.
  • add parentheses around the result of UnionTest.toString. This aligns the result with ChoiceItemType notation and avoids misunderstanding when an occurrence indicator is appended later on.
  • add a few tests.

GuntherRademacher avatar Jun 24 '24 16:06 GuntherRademacher