Skip to content

Commit 50d9903

Browse files
committed
another test case + enforce keyword is the first real token
update blob to allow build
1 parent b7aa9a2 commit 50d9903

10 files changed

+34
-24
lines changed

lib/std/zig/Parse.zig

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,22 +370,24 @@ fn parseContainerMembers(p: *Parse) !Members {
370370
trailing = p.token_tags[p.tok_i - 1] == .semicolon;
371371
},
372372
.keyword_autotranslated => {
373-
_ = p.assertToken(.keyword_autotranslated);
374-
var temp_token: Node.Index = 1;
373+
const token = p.assertToken(.keyword_autotranslated);
375374
p.expectSemicolon(.expected_semi_after_decl, false) catch |err| {
376375
switch (err) {
377376
error.OutOfMemory => return error.OutOfMemory,
378-
error.ParseError => {
379-
p.findNextContainerMember();
380-
temp_token = null_node;
381-
},
377+
error.ParseError => continue,
382378
}
383379
};
384380

385-
if (temp_token != 0) {
386-
p.is_autotranslated = true;
381+
if (p.nodes.len != 1) {
382+
try p.warnMsg(.{
383+
.tag = .autotranslated_not_first_token,
384+
.token = token,
385+
});
386+
continue;
387387
}
388388

389+
p.is_autotranslated = true;
390+
389391
trailing = p.token_tags[p.tok_i - 1] == .semicolon;
390392
},
391393
.eof, .r_brace => {

lib/std/zig/parser_test.zig

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,7 @@ test "zig fmt: grouped expressions (parentheses)" {
610610

611611
test "zig fmt: c pointer type" {
612612
try testCanonical(
613-
\\test {
614-
\\ const x: [*c]u8 = 0;
615-
\\}
613+
\\pub extern fn repro() [*c]const u8;
616614
\\
617615
);
618616
}
@@ -716,11 +714,9 @@ test "zig fmt: sentinel pointer with modifiers" {
716714

717715
test "zig fmt: c pointer with modifiers" {
718716
try testCanonical(
719-
\\test {
720-
\\ const x: [*c]u32 = undefined;
721-
\\ const y: [*c]allowzero align(8) addrspace(.generic) const volatile u32 = undefined;
722-
\\ const z: [*c]allowzero align(8:4:2) addrspace(.generic) const volatile u32 = undefined;
723-
\\}
717+
\\const x: [*c]u32 = undefined;
718+
\\const y: [*c]allowzero align(8) addrspace(.generic) const volatile u32 = undefined;
719+
\\const z: [*c]allowzero align(8:4:2) addrspace(.generic) const volatile u32 = undefined;
724720
\\
725721
);
726722
}
@@ -1248,9 +1244,7 @@ test "zig fmt: infix operator and then multiline string literal over multiple li
12481244

12491245
test "zig fmt: C pointers" {
12501246
try testCanonical(
1251-
\\test {
1252-
\\ const Ptr = [*c]i32;
1253-
\\}
1247+
\\const Ptr = [*c]i32;
12541248
\\
12551249
);
12561250
}

lib/std/zig/perf_test.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn main() !void {
1111
var i: usize = 0;
1212
var timer = try std.time.Timer.start();
1313
const start = timer.lap();
14-
const iterations = 1000;
14+
const iterations = 100;
1515
var memory_used: usize = 0;
1616
while (i < iterations) : (i += 1) {
1717
memory_used += testOnce();

src/main.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4416,6 +4416,8 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*Compilati
44164416
const formatted = try tree.render(comp.gpa);
44174417
defer comp.gpa.free(formatted);
44184418

4419+
try zig_file.writeAll("thisfileisautotranslatedfromc;\n");
4420+
44194421
try zig_file.writeAll(formatted);
44204422

44214423
man.writeManifest() catch |err| warn("failed to write cache manifest: {s}", .{

stage1/zig1.wasm

189 KB
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export fn a() void {
2+
const foo: [*c]u8 = undefined;
3+
_ = foo;
4+
}
5+
6+
thisfileisautotranslatedfromc;
7+
8+
// error
9+
// backend=stage2
10+
// target=native
11+
//
12+
// :6:1: error: thisfileisautotranslatedfromc must be the first token in the file

test/cases/compile_errors/implicit_cast_to_c_ptr_from_int.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ export fn entry2() void {
1414
//
1515
// :5:21: error: expected type '[*c]u8', found 'u65'
1616
// :5:21: note: unsigned 64-bit int cannot represent all possible unsigned 65-bit values
17-
// :8:36: error: expected type '[*c]u8', found 'comptime_int'
17+
// :8:36: error: expected type '[*c]u8', found 'comptime_int'

test/cases/compile_errors/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ export fn entry2() void {
3030
// :8:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'
3131
// :18:35: error: expected type '[*c][*c]const u8', found '*[*]u8'
3232
// :18:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'
33-
// :18:35: note: mutable '[*]u8' allows illegal null values stored to type '[*c]const u8'
33+
// :18:35: note: mutable '[*]u8' allows illegal null values stored to type '[*c]const u8'

test/cases/compile_errors/old_fn_ptr_in_extern_context.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ comptime {
1919
// :4:8: note: use '*const ' to make a function pointer type
2020
// :10:13: error: C pointers cannot point to non-C-ABI-compatible type '[4]fn () callconv(.C) void'
2121
// :10:13: note: type has no guaranteed in-memory representation
22-
// :10:13: note: use '*const ' to make a function pointer type
22+
// :10:13: note: use '*const ' to make a function pointer type

test/cases/compile_errors/type_mismatch_in_C_prototype_with_varargs.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ export fn main() void {
1414
//
1515
// :7:22: error: expected type '?fn ([*c]u8, ...) callconv(.C) void', found 'fn ([*:0]u8, ...) callconv(.C) void'
1616
// :7:22: note: parameter 0 '[*:0]u8' cannot cast into '[*c]u8'
17-
// :7:22: note: '[*c]u8' could have null values which are illegal in type '[*:0]u8'
17+
// :7:22: note: '[*c]u8' could have null values which are illegal in type '[*:0]u8'

0 commit comments

Comments
 (0)