cli: parse dereferenced places in inline borrow arguments

This commit is contained in:
dev committed 2026-10-07 22:55:10 +03:00
1 parent 65e7a0a97c
commit 5f76e92ff3
17 files changed
+185 -2

No files matched your search

+28
View File
@@ -115,6 +115,7 @@ with tempfile.TemporaryDirectory(prefix="aji-format-") as directory:
b"module m fn f(p:own<own<u64> >)->u64 effects [] {let n=(1u64+2u64)*3u64;return n>>1u64;}",
b"module m fn f()->void effects [] {select { recv(rx){ok(x)=>{},closed=>{},cancelled=>{},} cancelled=>{},}}",
b"module m fn f()->void effects [] {let p=P{a:1u64, // lit \t\nb:2u64};\n\n\nlet n=not (true and false);}",
b"module m fn f(p:mut<u64>)->void effects [] {apply(ref // shared\n*p,mut *p);}",
]
for i, source in enumerate(cases):
sample = root / f"case{i}.aji"
@@ -123,6 +124,33 @@ with tempfile.TemporaryDirectory(prefix="aji-format-") as directory:
sample.write_bytes(text)
assert cli("fmt", sample) == text, (i, text)
cli("fmt", "--check", sample)
# The grammar permits inline dereferenced places without parentheses.
# Both spellings must lower identically; formatting preserves the new
# prefix boundary and comments without introducing grouping tokens.
bare = root / "deref.aji"
grouped = root / "deref-grouped.aji"
source = (REPO / "tests/conformance/source/deref_arguments/mutable.aji").read_bytes()
for gap in (b" ", b"\r\n", " // λ\n".encode()):
bare.write_bytes(source.replace(b"mut *p", b"mut" + gap + b"*p")
.replace(b"ref *p", b"ref" + gap + b"*p"))
grouped.write_bytes(source.replace(b"mut *p", b"mut (*p)").replace(b"ref *p", b"ref (*p)"))
air = cli("lower", bare)
assert cli("lower", grouped) == air
cli("check", bare)
result = json.loads(cli("run", "--fuel", "100000", bare))
assert result["value"] == 42
text = cli("fmt", bare)
bare.write_bytes(text)
assert cli("fmt", bare) == text
assert cli("lower", bare) == air
cli("fmt", "--check", bare)
text = cli("fmt", grouped)
assert b"ref (*p)" in text and b"mut (*p)" in text, text
grouped.write_bytes(text)
assert cli("fmt", grouped) == text
assert cli("lower", grouped) == air
cli("fmt", "--check", grouped)
if b"// lit" in source:
assert b"// lit \t\n b: 2u64" in text
assert b"not (true and false)" in text