diag: explain pointer-sized cast restrictions in source advice
This commit is contained in:
1 parent
8a714ba6de
commit
6a02659f31
23 files changed
+96
-8
No files matched your search
@@ -157,4 +157,29 @@ with tempfile.TemporaryDirectory(prefix='source-advice-', dir=cache) as director
|
||||
probe.write_text('module probe\n' + body + '\n')
|
||||
advice(json.loads(cli('check', probe, code=1)), kind)
|
||||
|
||||
# Pointer-sized widening is rejected independently of target/value range.
|
||||
# Identity casts follow the same source rule instead of leaking AIR E1002.
|
||||
for source_type, target_type in [
|
||||
('u8', 'usize'), ('usize', 'u64'), ('i8', 'isize'),
|
||||
('isize', 'i64'), ('usize', 'usize'), ('isize', 'isize'),
|
||||
]:
|
||||
base = (f'module probe\nfn f(x: {source_type}) -> {target_type} effects [] '
|
||||
'{ return x OP ' + target_type + '; }\n'
|
||||
'fn main() -> void effects [] {}\n')
|
||||
probe.write_text(base.replace('OP', 'as'))
|
||||
error = json.loads(cli('check', probe, code=1))
|
||||
advice(error, 'numeric_cast_modes', ['as!', 'as%'])
|
||||
assert (error['from'], error['to']) == (source_type, target_type), error
|
||||
assert 'air_line' not in error and 'air_col' not in error, error
|
||||
for command in ('lower', 'run', 'report', 'explore'):
|
||||
assert json.loads(cli(command, probe, code=1)) == error
|
||||
for spelling in ('as!', 'as%'):
|
||||
probe.write_text(base.replace('OP', spelling))
|
||||
cli('check', probe)
|
||||
for spelling in ('u8', 'u64', 'i64'):
|
||||
probe.write_text(f'module probe\nfn f(x: {spelling}) -> {spelling} effects [] '
|
||||
f'{{ return x as {spelling}; }}\n'
|
||||
'fn main() -> void effects [] {}\n')
|
||||
cli('check', probe)
|
||||
|
||||
print(f'source repair advice: {checks} checks passed')
|
||||
Reference in new issue
Block a user