Skip to content

Commit 68bacad

Browse files
authored
Merge pull request #15643 from Vexu/fixes
make `@call` compile errors match regular calls
2 parents 6f418c1 + 5aa9628 commit 68bacad

11 files changed

+230
-132
lines changed

lib/std/os/linux/x86.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub fn syscall6(
108108
);
109109
}
110110

111-
pub fn socketcall(call: usize, args: [*]usize) usize {
111+
pub fn socketcall(call: usize, args: [*]const usize) usize {
112112
return asm volatile ("int $0x80"
113113
: [ret] "={eax}" (-> usize),
114114
: [number] "{eax}" (@enumToInt(SYS.socketcall)),

src/Module.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6098,7 +6098,7 @@ pub const PeerTypeCandidateSrc = union(enum) {
60986098
none: void,
60996099
/// When we want to know the the src of candidate i, look up at
61006100
/// index i in this slice
6101-
override: []?LazySrcLoc,
6101+
override: []const ?LazySrcLoc,
61026102
/// resolvePeerTypes originates from a @TypeOf(...) call
61036103
typeof_builtin_call_node_offset: i32,
61046104

src/Sema.zig

Lines changed: 160 additions & 111 deletions
Large diffs are not rendered by default.

src/link/MachO/Atom.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn addRelocation(macho_file: *MachO, atom_index: Index, reloc: Relocation) !
116116
return addRelocations(macho_file, atom_index, &[_]Relocation{reloc});
117117
}
118118

119-
pub fn addRelocations(macho_file: *MachO, atom_index: Index, relocs: []Relocation) !void {
119+
pub fn addRelocations(macho_file: *MachO, atom_index: Index, relocs: []const Relocation) !void {
120120
const gpa = macho_file.base.allocator;
121121
const gop = try macho_file.relocs.getOrPut(gpa, atom_index);
122122
if (!gop.found_existing) {

src/print_air.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,6 @@ const Writer = struct {
917917

918918
try s.writeAll("\n");
919919
try s.writeByteNTimes(' ', old_indent);
920-
try s.writeAll("}");
921920
}
922921

923922
fn writeWasmMemorySize(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {

test/behavior/array.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ test "array init of container level array variable" {
696696
test "runtime initialized sentinel-terminated array literal" {
697697
var c: u16 = 300;
698698
const f = &[_:0x9999]u16{c};
699-
const g = @ptrCast(*[4]u8, f);
699+
const g = @ptrCast(*const [4]u8, f);
700700
try std.testing.expect(g[2] == 0x99);
701701
try std.testing.expect(g[3] == 0x99);
702702
}

test/behavior/basic.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,3 +1200,10 @@ test "arrays and vectors with big integers" {
12001200
try expect(b[0] == comptime std.math.maxInt(Int));
12011201
}
12021202
}
1203+
1204+
test "pointer to struct literal with runtime field is constant" {
1205+
const S = struct { data: usize };
1206+
var runtime_zero: usize = 0;
1207+
const ptr = &S{ .data = runtime_zero };
1208+
try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_const);
1209+
}

test/behavior/error.zig

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -705,22 +705,6 @@ test "error union payload is properly aligned" {
705705
if (blk.a != 1) unreachable;
706706
}
707707

708-
test "ret_ptr doesn't cause own inferred error set to be resolved" {
709-
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
710-
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
711-
712-
const S = struct {
713-
fn foo() !void {}
714-
715-
fn doTheTest() !void {
716-
errdefer @compileError("bad");
717-
718-
return try @This().foo();
719-
}
720-
};
721-
try S.doTheTest();
722-
}
723-
724708
test "simple else prong allowed even when all errors handled" {
725709
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
726710
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
@@ -928,3 +912,28 @@ test "optional error set return type" {
928912
try expect(null == S.foo(true));
929913
try expect(E.A == S.foo(false).?);
930914
}
915+
916+
test "try used in recursive function with inferred error set" {
917+
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
918+
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
919+
920+
const Value = union(enum) {
921+
values: []const @This(),
922+
b,
923+
924+
fn x(value: @This()) !void {
925+
switch (value.values[0]) {
926+
.values => return try x(value.values[0]),
927+
.b => return error.a,
928+
}
929+
}
930+
};
931+
const a = Value{
932+
.values = &[1]Value{
933+
.{
934+
.values = &[1]Value{.{ .b = {} }},
935+
},
936+
},
937+
};
938+
try expectError(error.a, Value.x(a));
939+
}

test/cases/compile_errors/member_function_arg_mismatch.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ pub export fn entry() void {
66
var s: S = undefined;
77
s.foo(true);
88
}
9+
pub export fn entry2() void {
10+
var s: S = undefined;
11+
@call(.auto, s.foo, .{true});
12+
}
913

1014
// error
1115
// backend=stage2
1216
// target=native
1317
//
1418
// :7:6: error: member function expected 2 argument(s), found 1
1519
// :3:5: note: function declared here
20+
// :11:19: error: member function expected 2 argument(s), found 1
21+
// :3:5: note: function declared here
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
fn foo(a: anytype) !void {
2+
if (a == 0) return error.A;
3+
return error.B;
4+
}
5+
const Error = error{ A, B };
6+
export fn entry() void {
7+
const info = @typeInfo(@TypeOf(foo));
8+
const ret_type = info.Fn.return_type.?;
9+
const error_set = @typeInfo(ret_type).ErrorUnion.error_set;
10+
_ = Error || error_set;
11+
}
12+
13+
// error
14+
// backend=stage2
15+
// target=native
16+
//
17+
// :10:15: error: unable to resolve inferred error set of generic function
18+
// :1:1: note: generic function declared here
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pub export fn entry(param: usize) usize {
2+
return struct{ param };
3+
}
4+
5+
// error
6+
// backend=stage2
7+
// target=native
8+
//
9+
// :2:12: error: expected type 'usize', found 'type'
10+
// :1:35: note: function return type declared here

0 commit comments

Comments
 (0)