docs← Back to article

Markdown for LLMs

LDC-E2122 — A comparison across two different enumerations

The source Markdown for this article. Copy it into your assistant or download it as a text file.

Download this articlePlain text ↗
# LDC-E2122 — A comparison across two different enumerations

## What it means

Members of an enumeration compare only within their own enumeration: the
comparison goes by the member identity, and members of different
enumerations are incomparable rather than unequal. At execution such a
comparison would poison the whole document instead of answering false, so
the compiler refuses the guard statically at the comparison.

The fix compares within one enumeration — a member against a value of the
same enumeration — or relates the two values through a relation instead of
comparing them directly. Ordering comparisons over enumerations are
refused the same way, since ordering is undefined over them entirely.

## Example

```law
language "law.core" version "0.2";
package demo.diagnostics version "0.1.0";
namespace "urn:law:demo:diagnostics";

entity P;
enum RiskLevel { Low, High }
enum Stage { First, Last }
relation level_of(p: P, l: RiskLevel) kind empirical;
relation stage_of(p: P, s: Stage) kind empirical;
relation ok(p: P) kind institutional;
rule R strict { for p: P; for l: RiskLevel; for s: Stage; when level_of(p, l) and stage_of(p, s) and (l == First); then ok(p); }
```

## Fix

```law
language "law.core" version "0.2";
package demo.diagnostics version "0.1.0";
namespace "urn:law:demo:diagnostics";

entity P;
enum RiskLevel { Low, High }
enum Stage { First, Last }
relation level_of(p: P, l: RiskLevel) kind empirical;
relation stage_of(p: P, s: Stage) kind empirical;
relation ok(p: P) kind institutional;
rule R strict { for p: P; for l: RiskLevel; for s: Stage; when level_of(p, l) and stage_of(p, s) and (l == Low); then ok(p); }
```

## Engine message

The engine reports this in its own wording:

```text
example.law:11:103: error LDC-E2122: «==»: operands belong to different enums — RiskLevel and Stage (§57): enum comparison goes by the member §38 stable qualified identity, and members of DIFFERENT enums are incomparable (errata E-0067) — execution answers TYPE_ERROR, poisoning the whole document, not `false`. Compare operands of one enum or relate them by a relation
```

## Related

- [Vocabulary](/constructs/vocabulary/) — how names are declared and which positions take them.