cli: restrict source scope names to lexical task operands

This commit is contained in:
dev committed 2026-10-07 19:50:49 +03:00
1 parent 364eb57bbc
commit 9001e56325
32 files changed
+307 -6

No files matched your search

+45
View File
@@ -100,4 +100,49 @@ with tempfile.TemporaryDirectory(prefix='aji-reasons-') as d:
ordinary.write_text('module ordinary fn main()->u64 effects [] {return true;}')
error = json.loads(invoke('check', ordinary, code=1))
assert error['code'] == 'E7005' and 'reason' not in error
# A scope name never reaches ordinary value lowering, including generic
# bodies and branch/block yields. No misleading move-repair is emitted.
scope_cases = REPO / 'tests/conformance/source/scopes'
for name in ('array', 'bare_array', 'bare_alias', 'block_yield', 'call_argument',
'discard', 'equality', 'generic_alias', 'if_yield', 'match_yield',
'move_alias', 'move_discard', 'return', 'scope_tail'):
path = scope_cases / f'{name}.aji'
error = json.loads(invoke('check', path, code=1))
assert (error['code'], error['reason'], error['name'], error['type']) == (
'E7006', 'invalid_expression', 's', 'scope'), error
assert 'suggestion' not in error, error
line = path.read_text().splitlines()[error['line'] - 1]
assert line[error['col'] - 1:].startswith(('s', 'move s')), (path, error)
assert json.loads(invoke('lower', path, code=1)) == error
for name, code, reason in (('borrow', 'E7006', 'invalid_place'),
('assignment', 'E7006', 'invalid_assignment'),
('moved_spawn', 'E7005', None),
('spawn_shadow', 'E7005', None),
('out_of_block', 'E7002', None),
('unjoined_shadow', 'E4301', None)):
error = json.loads(invoke('check', scope_cases / f'{name}.aji', code=1))
assert error['code'] == code and error.get('reason') == reason, error
# Imported specialized bodies retain the location of their forbidden
# scope use, rather than the call or the generated AIR.
entry.write_text('module app import dep; fn main()->u64 effects [] {dep.f::<u64>(42u64)}')
dep.write_text('module dep\nfn f<T:Copy>(x:T)->T effects [] {\n'
'scope s { let alias = move s; }\nmove x\n}\n')
error = json.loads(invoke('check', '--manifest', manifest, code=1))
assert (error['code'], error['reason'], error['file'], error['line'], error['col']) == (
'E7006', 'invalid_expression', dep.name, 3, 23), error
assert json.loads(invoke('lower', '--manifest', manifest, code=1)) == error
# Lexical completion and task/borrow cleanup are identical under both
# profiles and independent scheduler choices, even with shadowed names.
for name in ('nested_same_name', 'normal_exits', 'visible_outer', 'shadow_value'):
path = scope_cases / f'{name}.aji'
for quantum in (1, 5, 16):
args = ['--fuel', '10000', '--quantum', str(quantum), '--schedule-seed', '7']
assert json.loads(invoke('run', *args, path))['value'] == 42
result_file = root / 'scope-result.json'
invoke('run', '--profile', 'hosted', '--result-file', result_file, *args, path)
assert json.loads(result_file.read_text())['value'] == 42
print(f'source diagnostic reasons passed ({checks} checks; {fixtures} public E7006 fixtures)')