scrml.dev v0.7.1
Reference › Errors

E-VARIANT-AMBIGUOUS

A bare variant reference cannot be resolved to a unique enum.

Error Compile-time SPEC §14.10 (normative)

What it means

Bare variants (.Open) are shorthand that only works where the surrounding declaration fixes the type. If the position has no type context, or more than one enum in scope declares a variant of that name, the compiler has no basis to choose and refuses to guess. Per §14.10 bare variants are legal only at positions where the type is already fixed.

Minimal reproducer

This is the exact source compiled against the linked compiler and verified to produce E-VARIANT-AMBIGUOUS.

<program title="p">
    type A:enum = { Open, Shut }
    type B:enum = { Open, Closed }
    <chosen> = .Open
    <p>${@chosen}</p>
</>

How to fix

  1. Annotate the declaration. <chosen>: A = .Open fixes the type at the declaration and the bare variant resolves.
  2. Qualify the variant. A.Open names the enum explicitly. Preferred when two enums genuinely share a variant name and both are in scope.

Related

Specification

Normative text: §14.10, §18.0.3, §34. Spec lives at compiler/SPEC.md .

← Reference