cli: resolve struct len fields by receiver type
Use ordinary field lowering and declared field types for nominal receivers while preserving array and slice lengths. Make array field type hints available to chained access. Missing struct len now reports E7002 instead of the builtin-length E7005. Add 15 source regressions and imported generic CLI checks. Unit tests, all 1201 conformance cases, per-instruction collection for new cases, formatter corpus and original public check/lower compatibility pass.
This commit is contained in:
1 parent
184cb7b321
commit
1495650587
18 files changed
+244
-4
No files matched your search
@@ -41,7 +41,52 @@ with tempfile.TemporaryDirectory(prefix="aji-generics-") as directory:
|
||||
cli("report", "--manifest", manifest)
|
||||
cli("explore", "--max-runs", "8", "--manifest", manifest)
|
||||
assert "__aji_g_" in cli("lower", "--manifest", manifest)
|
||||
# Nominal `len` fields keep their declared types across module and
|
||||
# generic boundaries, including diagnostic source positions.
|
||||
lib.write_text("""module app.lib
|
||||
struct Field<T: Copy> { len: T }
|
||||
fn read<T: Copy>(value: ref<Field<T>>) -> T effects [] { return value.len; }
|
||||
fn make() -> Field<u32> effects [] { return Field::<u32> { len: 42u32 }; }
|
||||
""")
|
||||
entry.write_text("""module app.entry
|
||||
import app.lib;
|
||||
fn main() -> u32 effects [] {
|
||||
var value: app.lib.Field<u32> = app.lib.Field::<u32> { len: 41u32 };
|
||||
var flag: app.lib.Field<bool> = app.lib.Field::<bool> { len: true };
|
||||
assert(app.lib.read::<bool>(ref flag));
|
||||
assert(app.lib.make().len == 42u32);
|
||||
let one = 1;
|
||||
return one + app.lib.read::<u32>(ref value);
|
||||
}
|
||||
""")
|
||||
cli("check", "--manifest", manifest)
|
||||
canonical = cli("lower", "--manifest", manifest)
|
||||
assert canonical == cli("lower", "--manifest", manifest)
|
||||
assert "struct.get" in canonical and "borrow.field" in canonical
|
||||
assert "slice.len" not in canonical
|
||||
air.write_text(canonical)
|
||||
source_record = json.loads(cli("run", "--fuel", "100000", "--manifest", manifest))
|
||||
assert source_record["value"] == 42
|
||||
assert json.loads(cli("run", "--fuel", "100000", air)) == source_record
|
||||
cli("report", "--manifest", manifest)
|
||||
cli("explore", "--max-runs", "8", "--manifest", manifest)
|
||||
lib.write_text("""module app.lib
|
||||
struct Field<T: Copy> { count: T }
|
||||
fn read<T: Copy>(value: ref<Field<T>>) -> T effects [] { return value.len; }
|
||||
""")
|
||||
entry.write_text("""module app.entry
|
||||
import app.lib;
|
||||
fn main() -> u32 effects [] {
|
||||
var value: app.lib.Field<u32> = app.lib.Field::<u32> { count: 42u32 };
|
||||
return app.lib.read::<u32>(ref value);
|
||||
}
|
||||
""")
|
||||
for command in ("check", "lower", "report", "run", "explore"):
|
||||
error = json.loads(cli(command, "--manifest", manifest, code=1))
|
||||
assert error["code"] == "E7002" and error["field"] == "len"
|
||||
assert error["file"] == "lib.aji" and error["line"] == 3 and error["col"] == 65, error
|
||||
lib.write_text("module app.lib\nfn id<T: Copy>(value: T) -> T effects [] { assert(false); return value; }\n")
|
||||
entry.write_text("module app.entry\nimport app.lib;\nstruct Pair { value: u64 }\nfn main() -> u64 effects [] { return app.lib.id::<Pair>(Pair { value: 42 }).value; }\n")
|
||||
record = json.loads(cli("run", "--fuel", "1000000", "--manifest", manifest, code=4))
|
||||
assert record["source_location"]["file"] == "lib.aji"
|
||||
lib.write_text("module app.lib\nfn id<T: Copy>(value: T) -> T effects [] { return missing(value); }\n")
|
||||
|
||||
Reference in new issue
Block a user