Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion compiler/analysis/typechecker.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- **Qualified enum members now retain their lexical prefix.** `hide Color`
blocks `Color.Red`, while `seal except Color` permits it; containment no
longer checks the generated `Color_Red` constant name.
71 changes: 71 additions & 0 deletions tests/integration/enum_containment/test_enum_containment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/sh
# Qualified enum members retain their written prefix through enum lowering so
# lexical hide/seal checks see the same name the source used.
set -eu

SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
AE="$ROOT/build/ae"
[ -x "$AE" ] || { echo " [SKIP] enum_containment: $AE not built"; exit 0; }

TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT

cat >"$TMPDIR/hide.ae" <<'AE'
enum Color { Red, Blue }
main() {
{
hide Color
c = Color.Red
}
}
AE

cat >"$TMPDIR/seal.ae" <<'AE'
enum Color { Red, Blue }
main() {
keep = 1
{
seal except keep
c = Color.Red
}
}
AE

cat >"$TMPDIR/allowed.ae" <<'AE'
enum Color { Red, Blue }
main() {
{
seal except Color
c = Color.Red
}
}
AE

failed=0
reject() {
name="$1"
if "$AE" build "$TMPDIR/$name.ae" -o "$TMPDIR/$name" >"$TMPDIR/$name.log" 2>&1; then
echo " [FAIL] enum_containment: $name accepted a blocked enum prefix"
failed=1
return
fi
if ! grep -q "'Color' is hidden in this scope" "$TMPDIR/$name.log"; then
echo " [FAIL] enum_containment: $name failed without the containment diagnostic"
sed 's/^/ /' "$TMPDIR/$name.log" | head -10
failed=1
fi
}

reject hide
reject seal

if ! "$AE" build "$TMPDIR/allowed.ae" -o "$TMPDIR/allowed" >"$TMPDIR/allowed.log" 2>&1; then
echo " [FAIL] enum_containment: whitelisted enum prefix was rejected"
sed 's/^/ /' "$TMPDIR/allowed.log" | head -10
failed=1
fi

[ "$failed" -eq 0 ] || exit 1

echo " [PASS] enum_containment: hidden and sealed prefixes reject; whitelist accepts"