test(ir): lock call lowering with .ir snapshots + classification tests (A3.2 convergence step 1)
Test-first scaffolding before the CallPlan convergence — no call-code change. Locks current call behavior so the later lowerCall rewrite is guarded. - .ir snapshots for representative call forms: 0031 (direct local-fn + dot-shorthand enum ctor), 0032 (UFCS/struct method), 0301 (closure/ fn-pointer slot), 0400 (protocol dispatch + static-through-impl). - New focused example 0044-basic-default-arg-expansion + .ir snapshot, pinning call-site default expansion (scale(5)->scale(ctx,5,2), label(1)->label(ctx,1,"v","!")). Foreign-class instance+static is already pinned by the existing FFI .ir set. - Broaden calls.test.zig (scope-free classification): remaining reflection builtins, sqrt->f64, cast->resolved type arg, enum_literal->target_type. 1033 (#caller_location) was rejected as a snapshot: it embeds the absolute source path as a length-typed string that normalize_ir can't reconcile; default-arg coverage uses the path-free 0044 instead. Gate green: zig build, zig build test, tests/run_examples.sh -> 357/0.
This commit is contained in:
@@ -29,10 +29,24 @@ test "calls: builtin and reflection result types, unknown fallthrough" {
|
||||
const cases = [_]struct { name: []const u8, want: TypeId }{
|
||||
.{ .name = "size_of", .want = .s64 },
|
||||
.{ .name = "align_of", .want = .s64 },
|
||||
// Reflection builtins (resolved by callee name, outside the
|
||||
// `resolveBuiltin` table) — each must keep its own result tag so a
|
||||
// pack-fn caller boxes the value with the right type.
|
||||
.{ .name = "type_name", .want = .string },
|
||||
.{ .name = "type_eq", .want = .bool },
|
||||
.{ .name = "has_impl", .want = .bool },
|
||||
.{ .name = "field_count", .want = .s64 },
|
||||
.{ .name = "field_index", .want = .s64 },
|
||||
.{ .name = "field_name", .want = .string },
|
||||
.{ .name = "error_tag_name", .want = .string },
|
||||
.{ .name = "is_comptime", .want = .bool },
|
||||
.{ .name = "is_flags", .want = .bool },
|
||||
.{ .name = "type_of", .want = .any },
|
||||
.{ .name = "field_value", .want = .any },
|
||||
.{ .name = "__interp_print_frames", .want = .void },
|
||||
// A math builtin with a non-`f32` argument widens to `f64` (the int
|
||||
// literal arg is not `f32`, so the `f32` fast-path is not taken).
|
||||
.{ .name = "sqrt", .want = .f64 },
|
||||
// Unknown bare callee with no builtin / declared fn / scope binding
|
||||
// types as unresolved, not a fabricated guess.
|
||||
.{ .name = "definitely_not_a_fn", .want = .unresolved },
|
||||
@@ -44,3 +58,39 @@ test "calls: builtin and reflection result types, unknown fallthrough" {
|
||||
try std.testing.expectEqual(tc.want, l.inferExprType(&call));
|
||||
}
|
||||
}
|
||||
|
||||
test "calls: cast result type is its resolved type argument" {
|
||||
const alloc = std.testing.allocator;
|
||||
var module = ir_mod.Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var l = Lowering.init(&module);
|
||||
|
||||
// `cast(s64) x` types as the resolved target type — the first arg is the
|
||||
// type expression, resolved via `resolveTypeArg` (a primitive needs no
|
||||
// scope / registration).
|
||||
var target = node(.{ .type_expr = .{ .name = "s64" } });
|
||||
var value = node(.{ .int_literal = .{ .value = 1 } });
|
||||
var cast_args = [_]*Node{ &target, &value };
|
||||
var cast_callee = node(.{ .identifier = .{ .name = "cast" } });
|
||||
var cast_call = node(.{ .call = .{ .callee = &cast_callee, .args = &cast_args } });
|
||||
try std.testing.expectEqual(TypeId.s64, l.inferExprType(&cast_call));
|
||||
}
|
||||
|
||||
test "calls: dot-shorthand enum construction types as the target type" {
|
||||
const alloc = std.testing.allocator;
|
||||
var module = ir_mod.Module.init(alloc);
|
||||
defer module.deinit();
|
||||
var l = Lowering.init(&module);
|
||||
|
||||
// `.Variant(args)` carries no callee name; its result type is whatever
|
||||
// target type is in scope. Absent one, it stays unresolved (not a guess).
|
||||
var enum_callee = node(.{ .enum_literal = .{ .name = "Variant" } });
|
||||
var arg = node(.{ .int_literal = .{ .value = 1 } });
|
||||
var args = [_]*Node{&arg};
|
||||
var enum_call = node(.{ .call = .{ .callee = &enum_callee, .args = &args } });
|
||||
|
||||
try std.testing.expectEqual(TypeId.unresolved, l.inferExprType(&enum_call));
|
||||
|
||||
l.target_type = .s32;
|
||||
try std.testing.expectEqual(TypeId.s32, l.inferExprType(&enum_call));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user