cli: search expected source types iteratively
This commit is contained in:
1 parent
e862e03f2b
commit
e3f4695efe
5 files changed
+504
-57
No files matched your search
@@ -22,8 +22,9 @@ def source(kind, depth):
|
||||
if kind == 'not':
|
||||
ty, setup, expression = 'bool', '', 'not ' * depth + 'false'
|
||||
instructions, expected = 2 * depth + 2, bool(depth % 2)
|
||||
elif kind == 'neg':
|
||||
ty, setup, expression = 'i64', 'let n: i64 = 1i64; ', '- ' * depth + 'n'
|
||||
elif kind in ('neg', 'inferred_neg'):
|
||||
setup = 'let n = 1; ' if kind == 'inferred_neg' else 'let n: i64 = 1i64; '
|
||||
ty, expression = 'i64', '- ' * depth + 'n'
|
||||
instructions, expected = 2 * depth + 2, 1 if depth % 2 == 0 else -1
|
||||
else:
|
||||
ty, setup = 'i64', ''
|
||||
@@ -35,7 +36,7 @@ def source(kind, depth):
|
||||
with tempfile.TemporaryDirectory(prefix='aji-expression-depth-') as directory:
|
||||
root = Path(directory)
|
||||
for depth in (0, 1, 16, 1024, 16384, 65536):
|
||||
for kind in ('not', 'neg', 'cast'):
|
||||
for kind in ('not', 'neg', 'cast', 'inferred_neg'):
|
||||
path = root / f'{kind}-{depth}.aji'
|
||||
text, instructions, expected = source(kind, depth)
|
||||
path.write_text(text)
|
||||
@@ -58,6 +59,17 @@ with tempfile.TemporaryDirectory(prefix='aji-expression-depth-') as directory:
|
||||
print(f'unary depth: {kind} {depth}', flush=True)
|
||||
|
||||
for depth in (1024, 16384, 65536):
|
||||
# A cast removes the expected-use hint; deep traversal must retain
|
||||
# E7007 at the original unsuffixed initializer, without new inference.
|
||||
hint_header = 'module depth\nfn main() -> i64 effects [] { let n = '
|
||||
path = root / f'inferred-no-hint-{depth}.aji'
|
||||
path.write_text(hint_header + '1; return (' + '- ' * depth + 'n) as i64; }\n')
|
||||
error = json.loads(cli('check', path, code=1))
|
||||
col = len(hint_header.split('\n')[-1]) + 1
|
||||
assert (error['code'], error['line'], error['col'], error['file']) == ('E7007', 2, col, str(path)), error
|
||||
for command in ('lower', 'run', 'report', 'explore'):
|
||||
assert json.loads(cli(command, path, code=1)) == error
|
||||
|
||||
header = 'module depth\nfn main() -> i64 effects [] { return '
|
||||
path = root / f'deref-{depth}.aji'
|
||||
path.write_text(header + '* ' * depth + '1i64; }\n')
|
||||
|
||||
Reference in new issue
Block a user