Skip to content

Implicit enum values after explicit numeric variants duplicate the explicit value #349

@aspizu

Description

@aspizu

Repro

tmp=$(mktemp -d /tmp/goboscript-enum-mixed-XXXXXX)
printf 'costumes "blank.svg";\n\n' > "$tmp/stage.gs"
printf 'costumes "blank.svg";\n\nenum Direction {\n    A = "A",\n    B,\n    C = "C",\n    D,\n    E = 2,\n    F,\n}\n\nonflag {\n    say Direction.B;\n    say Direction.D;\n    say Direction.F;\n}\n' > "$tmp/main.gs"
printf '<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"></svg>\n' > "$tmp/blank.svg"
cargo run --quiet -- build "$tmp"
python3 - <<'PY' "$tmp/$(basename "$tmp").sb3"
import json, sys, zipfile
with zipfile.ZipFile(sys.argv[1]) as z:
    p=json.loads(z.read('project.json'))
blocks=p['targets'][1]['blocks']
for b in blocks.values():
    if b.get('opcode') == 'looks_say':
        print(b['inputs']['MESSAGE'])
PY

Observed message constants:

[1, [4, 0]]
[1, [4, 1]]
[1, [4, 2]]

So Direction.F compiles to 2 even though Direction.E is also explicitly 2.

Docs in docs/language/enums.md show this exact mixed enum pattern and mark F as 3.

Expected

After an explicit numeric enum value, the next implicit enum value should continue at the following number. Here Direction.F should compile to 3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions