/
compile_errors.zig
6917 lines (6368 loc) · 191 KB
/
compile_errors.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const tests = @import("tests.zig");
const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.addCase(x: {
var tc = cases.create("@newStackCall on unsupported target",
\\export fn entry() void {
\\ var buf: [10]u8 align(16) = undefined;
\\ @newStackCall(&buf, foo);
\\}
\\fn foo() void {}
, "tmp.zig:3:5: error: target arch 'wasm32' does not support @newStackCall");
tc.target = tests.Target{
.Cross = tests.CrossTarget{
.arch = .wasm32,
.os = .wasi,
.abi = .none,
},
};
break :x tc;
});
cases.add(
"incompatible sentinels",
\\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
\\ return ptr;
\\}
\\export fn entry2(ptr: [*]u8) [*:0]u8 {
\\ return ptr;
\\}
\\export fn entry3() void {
\\ var array: [2:0]u8 = [_:255]u8{1, 2};
\\}
\\export fn entry4() void {
\\ var array: [2:0]u8 = [_]u8{1, 2};
\\}
,
"tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'",
"tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel",
"tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",
"tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel",
"tmp.zig:8:35: error: expected type '[2:0]u8', found '[2:255]u8'",
"tmp.zig:8:35: note: destination array requires a terminating '0' sentinel, but source array has a terminating '255' sentinel",
"tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'",
"tmp.zig:11:31: note: destination array requires a terminating '0' sentinel",
);
cases.add(
"empty switch on an integer",
\\export fn entry() void {
\\ var x: u32 = 0;
\\ switch(x) {}
\\}
,
"tmp.zig:3:5: error: switch must handle all possibilities",
);
cases.add(
"incorrect return type",
\\ pub export fn entry() void{
\\ _ = foo();
\\ }
\\ const A = struct {
\\ a: u32,
\\ };
\\ fn foo() A {
\\ return bar();
\\ }
\\ const B = struct {
\\ a: u32,
\\ };
\\ fn bar() B {
\\ unreachable;
\\ }
,
"tmp.zig:8:16: error: expected type 'A', found 'B'",
);
cases.add(
"regression test #2980: base type u32 is not type checked properly when assigning a value within a struct",
\\const Foo = struct {
\\ ptr: ?*usize,
\\ uval: u32,
\\};
\\fn get_uval(x: u32) !u32 {
\\ return error.NotFound;
\\}
\\export fn entry() void {
\\ const afoo = Foo{
\\ .ptr = null,
\\ .uval = get_uval(42),
\\ };
\\}
,
"tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'",
);
cases.add(
"asigning to struct or union fields that are not optionals with a function that returns an optional",
\\fn maybe(is: bool) ?u8 {
\\ if (is) return @as(u8, 10) else return null;
\\}
\\const U = union {
\\ Ye: u8,
\\};
\\const S = struct {
\\ num: u8,
\\};
\\export fn entry() void {
\\ var u = U{ .Ye = maybe(false) };
\\ var s = S{ .num = maybe(false) };
\\}
,
"tmp.zig:11:27: error: expected type 'u8', found '?u8'",
);
cases.add(
"missing result type for phi node",
\\fn foo() !void {
\\ return anyerror.Foo;
\\}
\\export fn entry() void {
\\ foo() catch 0;
\\}
,
"tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'",
);
cases.add(
"atomicrmw with enum op not .Xchg",
\\export fn entry() void {
\\ const E = enum(u8) {
\\ a,
\\ b,
\\ c,
\\ d,
\\ };
\\ var x: E = .a;
\\ _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);
\\}
,
"tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg",
);
cases.add(
"disallow coercion from non-null-terminated pointer to null-terminated pointer",
\\extern fn puts(s: [*:0]const u8) c_int;
\\pub fn main() void {
\\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'};
\\ const no_zero_ptr: [*]const u8 = &no_zero_array;
\\ _ = puts(no_zero_ptr);
\\}
,
"tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'",
);
cases.add(
"atomic orderings of atomicStore Acquire or AcqRel",
\\export fn entry() void {
\\ var x: u32 = 0;
\\ @atomicStore(u32, &x, 1, .Acquire);
\\}
,
"tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel",
);
cases.add(
"missing const in slice with nested array type",
\\const Geo3DTex2D = struct { vertices: [][2]f32 };
\\pub fn getGeo3DTex2D() Geo3DTex2D {
\\ return Geo3DTex2D{
\\ .vertices = [_][2]f32{
\\ [_]f32{ -0.5, -0.5},
\\ },
\\ };
\\}
\\export fn entry() void {
\\ var geo_data = getGeo3DTex2D();
\\}
,
"tmp.zig:4:30: error: expected type '[][2]f32', found '[1][2]f32'",
);
cases.add(
"slicing of global undefined pointer",
\\var buf: *[1]u8 = undefined;
\\export fn entry() void {
\\ _ = buf[0..1];
\\}
,
"tmp.zig:3:12: error: non-zero length slice of undefined pointer",
);
cases.add(
"using invalid types in function call raises an error",
\\const MenuEffect = enum {};
\\fn func(effect: MenuEffect) void {}
\\export fn entry() void {
\\ func(MenuEffect.ThisDoesNotExist);
\\}
,
"tmp.zig:1:20: error: enums must have 1 or more fields",
"tmp.zig:4:20: note: referenced here",
);
cases.add(
"store vector pointer with unknown runtime index",
\\export fn entry() void {
\\ var v: @Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
\\
\\ var i: u32 = 0;
\\ storev(&v[i], 42);
\\}
\\
\\fn storev(ptr: var, val: i32) void {
\\ ptr.* = val;
\\}
,
"tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32",
);
cases.add(
"load vector pointer with unknown runtime index",
\\export fn entry() void {
\\ var v: @Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
\\
\\ var i: u32 = 0;
\\ var x = loadv(&v[i]);
\\}
\\
\\fn loadv(ptr: var) i32 {
\\ return ptr.*;
\\}
,
"tmp.zig:9:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32",
);
cases.add(
"using an unknown len ptr type instead of array",
\\const resolutions = [*][*]const u8{
\\ "[320 240 ]",
\\ null,
\\};
\\comptime {
\\ _ = resolutions;
\\}
,
"tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'",
);
cases.add(
"comparison with error union and error value",
\\export fn entry() void {
\\ var number_or_error: anyerror!i32 = error.SomethingAwful;
\\ _ = number_or_error == error.SomethingAwful;
\\}
,
"tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'",
);
cases.add(
"switch with overlapping case ranges",
\\export fn entry() void {
\\ var q: u8 = 0;
\\ switch (q) {
\\ 1...2 => {},
\\ 0...255 => {},
\\ }
\\}
,
"tmp.zig:5:9: error: duplicate switch value",
);
cases.add(
"invalid optional type in extern struct",
\\const stroo = extern struct {
\\ moo: ?[*c]u8,
\\};
\\export fn testf(fluff: *stroo) void {}
,
"tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'",
);
cases.add(
"attempt to negate a non-integer, non-float or non-vector type",
\\fn foo() anyerror!u32 {
\\ return 1;
\\}
\\
\\export fn entry() void {
\\ const x = -foo();
\\}
,
"tmp.zig:6:15: error: negation of type 'anyerror!u32'",
);
cases.add(
"attempt to create 17 bit float type",
\\const builtin = @import("builtin");
\\comptime {
\\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } });
\\}
,
"tmp.zig:3:32: error: 17-bit float unsupported",
);
cases.add(
"wrong type for @Type",
\\export fn entry() void {
\\ _ = @Type(0);
\\}
,
"tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int'",
);
cases.add(
"@Type with non-constant expression",
\\const builtin = @import("builtin");
\\var globalTypeInfo : builtin.TypeInfo = undefined;
\\export fn entry() void {
\\ _ = @Type(globalTypeInfo);
\\}
,
"tmp.zig:4:15: error: unable to evaluate constant expression",
);
cases.add(
"@Type with TypeInfo.Int",
\\const builtin = @import("builtin");
\\export fn entry() void {
\\ _ = @Type(builtin.TypeInfo.Int {
\\ .is_signed = true,
\\ .bits = 8,
\\ });
\\}
,
"tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'",
);
cases.add(
"Struct unavailable for @Type",
\\export fn entry() void {
\\ _ = @Type(@typeInfo(struct { }));
\\}
,
"tmp.zig:2:15: error: @Type not availble for 'TypeInfo.Struct'",
);
cases.add(
"wrong type for result ptr to @asyncCall",
\\export fn entry() void {
\\ _ = async amain();
\\}
\\fn amain() i32 {
\\ var frame: @Frame(foo) = undefined;
\\ return await @asyncCall(&frame, false, foo);
\\}
\\fn foo() i32 {
\\ return 1234;
\\}
,
"tmp.zig:6:37: error: expected type '*i32', found 'bool'",
);
cases.add(
"shift amount has to be an integer type",
\\export fn entry() void {
\\ const x = 1 << &@as(u8, 10);
\\}
,
"tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8'",
"tmp.zig:2:17: note: referenced here",
);
cases.add(
"bit shifting only works on integer types",
\\export fn entry() void {
\\ const x = &@as(u8, 1) << 10;
\\}
,
"tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8'",
"tmp.zig:2:27: note: referenced here",
);
cases.add(
"struct depends on itself via optional field",
\\const LhsExpr = struct {
\\ rhsExpr: ?AstObject,
\\};
\\const AstObject = union {
\\ lhsExpr: LhsExpr,
\\};
\\export fn entry() void {
\\ const lhsExpr = LhsExpr{ .rhsExpr = null };
\\ const obj = AstObject{ .lhsExpr = lhsExpr };
\\}
,
"tmp.zig:1:17: error: struct 'LhsExpr' depends on itself",
"tmp.zig:5:5: note: while checking this field",
"tmp.zig:2:5: note: while checking this field",
);
cases.add(
"alignment of enum field specified",
\\const Number = enum {
\\ a,
\\ b align(i32),
\\};
\\export fn entry1() void {
\\ var x: Number = undefined;
\\}
,
"tmp.zig:3:13: error: structs and unions, not enums, support field alignment",
"tmp.zig:1:16: note: consider 'union(enum)' here",
);
cases.add(
"bad alignment type",
\\export fn entry1() void {
\\ var x: []align(true) i32 = undefined;
\\}
\\export fn entry2() void {
\\ var x: *align(@as(f64, 12.34)) i32 = undefined;
\\}
,
"tmp.zig:2:20: error: expected type 'u29', found 'bool'",
"tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'",
);
cases.addCase(x: {
var tc = cases.create("variable in inline assembly template cannot be found",
\\export fn entry() void {
\\ var sp = asm volatile (
\\ "mov %[foo], sp"
\\ : [bar] "=r" (-> usize)
\\ );
\\}
, "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs");
tc.target = tests.Target{
.Cross = tests.CrossTarget{
.arch = .x86_64,
.os = .linux,
.abi = .gnu,
},
};
break :x tc;
});
cases.add(
"indirect recursion of async functions detected",
\\var frame: ?anyframe = null;
\\
\\export fn a() void {
\\ _ = async rangeSum(10);
\\ while (frame) |f| resume f;
\\}
\\
\\fn rangeSum(x: i32) i32 {
\\ suspend {
\\ frame = @frame();
\\ }
\\ frame = null;
\\
\\ if (x == 0) return 0;
\\ var child = rangeSumIndirect(x - 1);
\\ return child + 1;
\\}
\\
\\fn rangeSumIndirect(x: i32) i32 {
\\ suspend {
\\ frame = @frame();
\\ }
\\ frame = null;
\\
\\ if (x == 0) return 0;
\\ var child = rangeSum(x - 1);
\\ return child + 1;
\\}
,
"tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself",
"tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here",
"tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here",
);
cases.add(
"non-async function pointer eventually is inferred to become async",
\\export fn a() void {
\\ var non_async_fn: fn () void = undefined;
\\ non_async_fn = func;
\\}
\\fn func() void {
\\ suspend;
\\}
,
"tmp.zig:5:1: error: 'func' cannot be async",
"tmp.zig:3:20: note: required to be non-async here",
"tmp.zig:6:5: note: suspends here",
);
cases.add(
"bad alignment in @asyncCall",
\\export fn entry() void {
\\ var ptr: async fn () void = func;
\\ var bytes: [64]u8 = undefined;
\\ _ = @asyncCall(&bytes, {}, ptr);
\\}
\\async fn func() void {}
,
"tmp.zig:4:21: error: expected type '[]align(16) u8', found '*[64]u8'",
);
cases.add(
"atomic orderings of fence Acquire or stricter",
\\export fn entry() void {
\\ @fence(.Monotonic);
\\}
,
"tmp.zig:2:12: error: atomic ordering must be Acquire or stricter",
);
cases.add(
"bad alignment in implicit cast from array pointer to slice",
\\export fn a() void {
\\ var x: [10]u8 = undefined;
\\ var y: []align(16) u8 = &x;
\\}
,
"tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'",
);
cases.add(
"result location incompatibility mismatching handle_is_ptr (generic call)",
\\export fn entry() void {
\\ var damn = Container{
\\ .not_optional = getOptional(i32),
\\ };
\\}
\\pub fn getOptional(comptime T: type) ?T {
\\ return 0;
\\}
\\pub const Container = struct {
\\ not_optional: i32,
\\};
,
"tmp.zig:3:36: error: expected type 'i32', found '?i32'",
);
cases.add(
"result location incompatibility mismatching handle_is_ptr",
\\export fn entry() void {
\\ var damn = Container{
\\ .not_optional = getOptional(),
\\ };
\\}
\\pub fn getOptional() ?i32 {
\\ return 0;
\\}
\\pub const Container = struct {
\\ not_optional: i32,
\\};
,
"tmp.zig:3:36: error: expected type 'i32', found '?i32'",
);
cases.add(
"const frame cast to anyframe",
\\export fn a() void {
\\ const f = async func();
\\ resume f;
\\}
\\export fn b() void {
\\ const f = async func();
\\ var x: anyframe = &f;
\\}
\\fn func() void {
\\ suspend;
\\}
,
"tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'",
"tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'",
);
cases.add(
"prevent bad implicit casting of anyframe types",
\\export fn a() void {
\\ var x: anyframe = undefined;
\\ var y: anyframe->i32 = x;
\\}
\\export fn b() void {
\\ var x: i32 = undefined;
\\ var y: anyframe->i32 = x;
\\}
\\export fn c() void {
\\ var x: @Frame(func) = undefined;
\\ var y: anyframe->i32 = &x;
\\}
\\fn func() void {}
,
"tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'",
"tmp.zig:7:28: error: expected type 'anyframe->i32', found 'i32'",
"tmp.zig:11:29: error: expected type 'anyframe->i32', found '*@Frame(func)'",
);
cases.add(
"wrong frame type used for async call",
\\export fn entry() void {
\\ var frame: @Frame(foo) = undefined;
\\ frame = async bar();
\\}
\\fn foo() void {
\\ suspend;
\\}
\\fn bar() void {
\\ suspend;
\\}
,
"tmp.zig:3:5: error: expected type '*@Frame(bar)', found '*@Frame(foo)'",
);
cases.add(
"@Frame() of generic function",
\\export fn entry() void {
\\ var frame: @Frame(func) = undefined;
\\}
\\fn func(comptime T: type) void {
\\ var x: T = undefined;
\\}
,
"tmp.zig:2:16: error: @Frame() of generic function",
);
cases.add(
"@frame() causes function to be async",
\\export fn entry() void {
\\ func();
\\}
\\fn func() void {
\\ _ = @frame();
\\}
,
"tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async",
"tmp.zig:5:9: note: @frame() causes function to be async",
);
cases.add(
"invalid suspend in exported function",
\\export fn entry() void {
\\ var frame = async func();
\\ var result = await frame;
\\}
\\fn func() void {
\\ suspend;
\\}
,
"tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async",
"tmp.zig:3:18: note: await here is a suspend point",
);
cases.add(
"async function indirectly depends on its own frame",
\\export fn entry() void {
\\ _ = async amain();
\\}
\\async fn amain() void {
\\ other();
\\}
\\fn other() void {
\\ var x: [@sizeOf(@Frame(amain))]u8 = undefined;
\\}
,
"tmp.zig:4:1: error: unable to determine async function frame of 'amain'",
"tmp.zig:5:10: note: analysis of function 'other' depends on the frame",
"tmp.zig:8:13: note: referenced here",
);
cases.add(
"async function depends on its own frame",
\\export fn entry() void {
\\ _ = async amain();
\\}
\\async fn amain() void {
\\ var x: [@sizeOf(@Frame(amain))]u8 = undefined;
\\}
,
"tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet",
"tmp.zig:5:13: note: referenced here",
);
cases.add(
"non async function pointer passed to @asyncCall",
\\export fn entry() void {
\\ var ptr = afunc;
\\ var bytes: [100]u8 align(16) = undefined;
\\ _ = @asyncCall(&bytes, {}, ptr);
\\}
\\fn afunc() void { }
,
"tmp.zig:4:32: error: expected async function, found 'fn() void'",
);
cases.add(
"runtime-known async function called",
\\export fn entry() void {
\\ _ = async amain();
\\}
\\fn amain() void {
\\ var ptr = afunc;
\\ _ = ptr();
\\}
\\async fn afunc() void {}
,
"tmp.zig:6:12: error: function is not comptime-known; @asyncCall required",
);
cases.add(
"runtime-known function called with async keyword",
\\export fn entry() void {
\\ var ptr = afunc;
\\ _ = async ptr();
\\}
\\
\\async fn afunc() void { }
,
"tmp.zig:3:15: error: function is not comptime-known; @asyncCall required",
);
cases.add(
"function with ccc indirectly calling async function",
\\export fn entry() void {
\\ foo();
\\}
\\fn foo() void {
\\ bar();
\\}
\\fn bar() void {
\\ suspend;
\\}
,
"tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async",
"tmp.zig:2:8: note: async function call here",
"tmp.zig:5:8: note: async function call here",
"tmp.zig:8:5: note: suspends here",
);
cases.add(
"capture group on switch prong with incompatible payload types",
\\const Union = union(enum) {
\\ A: usize,
\\ B: isize,
\\};
\\comptime {
\\ var u = Union{ .A = 8 };
\\ switch (u) {
\\ .A, .B => |e| unreachable,
\\ }
\\}
,
"tmp.zig:8:20: error: capture group with incompatible types",
"tmp.zig:8:9: note: type 'usize' here",
"tmp.zig:8:13: note: type 'isize' here",
);
cases.add(
"wrong type to @hasField",
\\export fn entry() bool {
\\ return @hasField(i32, "hi");
\\}
,
"tmp.zig:2:22: error: type 'i32' does not support @hasField",
);
cases.add(
"slice passed as array init type with elems",
\\export fn entry() void {
\\ const x = []u8{1, 2};
\\}
,
"tmp.zig:2:15: error: expected array type or [_], found slice",
);
cases.add(
"slice passed as array init type",
\\export fn entry() void {
\\ const x = []u8{};
\\}
,
"tmp.zig:2:15: error: expected array type or [_], found slice",
);
cases.add(
"inferred array size invalid here",
\\export fn entry() void {
\\ const x = [_]u8;
\\}
,
"tmp.zig:2:15: error: inferred array size invalid here",
);
cases.add(
"initializing array with struct syntax",
\\export fn entry() void {
\\ const x = [_]u8{ .y = 2 };
\\}
,
"tmp.zig:2:15: error: initializing array with struct syntax",
);
cases.add(
"compile error in struct init expression",
\\const Foo = struct {
\\ a: i32 = crap,
\\ b: i32,
\\};
\\export fn entry() void {
\\ var x = Foo{
\\ .b = 5,
\\ };
\\}
,
"tmp.zig:2:14: error: use of undeclared identifier 'crap'",
);
cases.add(
"undefined as field type is rejected",
\\const Foo = struct {
\\ a: undefined,
\\};
\\export fn entry1() void {
\\ const foo: Foo = undefined;
\\}
,
"tmp.zig:2:8: error: use of undefined value here causes undefined behavior",
);
cases.add(
"@hasDecl with non-container",
\\export fn entry() void {
\\ _ = @hasDecl(i32, "hi");
\\}
,
"tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'",
);
cases.add(
"field access of slices",
\\export fn entry() void {
\\ var slice: []i32 = undefined;
\\ const info = @typeOf(slice).unknown;
\\}
,
"tmp.zig:3:32: error: type '[]i32' does not support field access",
);
cases.add(
"peer cast then implicit cast const pointer to mutable C pointer",
\\export fn func() void {
\\ var strValue: [*c]u8 = undefined;
\\ strValue = strValue orelse "";
\\}
,
"tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'",
"tmp.zig:3:32: note: cast discards const qualifier",
);
cases.add(
"overflow in enum value allocation",
\\const Moo = enum(u8) {
\\ Last = 255,
\\ Over,
\\};
\\pub fn main() void {
\\ var y = Moo.Last;
\\}
,
"tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'",
);
cases.add(
"attempt to cast enum literal to error",
\\export fn entry() void {
\\ switch (error.Hi) {
\\ .Hi => {},
\\ }
\\}
,
"tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'",
);
cases.add(
"@sizeOf bad type",
\\export fn entry() usize {
\\ return @sizeOf(@typeOf(null));
\\}
,
"tmp.zig:2:20: error: no size available for type '(null)'",
);
cases.add(
"generic function where return type is self-referenced",
\\fn Foo(comptime T: type) Foo(T) {
\\ return struct{ x: T };
\\}
\\export fn entry() void {
\\ const t = Foo(u32) {
\\ .x = 1
\\ };
\\}
,
"tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches",
"tmp.zig:5:18: note: referenced here",
);
cases.add(
"@ptrToInt 0 to non optional pointer",
\\export fn entry() void {
\\ var b = @intToPtr(*i32, 0);
\\}
,
"tmp.zig:2:13: error: pointer type '*i32' does not allow address zero",
);
cases.add(
"cast enum literal to enum but it doesn't match",
\\const Foo = enum {
\\ a,
\\ b,
\\};
\\export fn entry() void {
\\ const x: Foo = .c;
\\}
,
"tmp.zig:6:20: error: enum 'Foo' has no field named 'c'",
"tmp.zig:1:13: note: 'Foo' declared here",
);
cases.add(
"discarding error value",
\\export fn entry() void {
\\ _ = foo();
\\}
\\fn foo() !void {
\\ return error.OutOfMemory;
\\}
,
"tmp.zig:2:12: error: error is discarded",
);
cases.add(
"volatile on global assembly",
\\comptime {
\\ asm volatile ("");
\\}
,
"tmp.zig:2:9: error: volatile is meaningless on global assembly",
);
cases.add(
"invalid multiple dereferences",
\\export fn a() void {
\\ var box = Box{ .field = 0 };
\\ box.*.field = 1;
\\}
\\export fn b() void {
\\ var box = Box{ .field = 0 };
\\ var boxPtr = &box;
\\ boxPtr.*.*.field = 1;
\\}
\\pub const Box = struct {
\\ field: i32,
\\};
,
"tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'",
"tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'",
);
cases.add(
"usingnamespace with wrong type",
\\usingnamespace void;
,
"tmp.zig:1:1: error: expected struct, enum, or union; found 'void'",
);
cases.add(
"ignored expression in while continuation",
\\export fn a() void {
\\ while (true) : (bad()) {}
\\}
\\export fn b() void {
\\ var x: anyerror!i32 = 1234;
\\ while (x) |_| : (bad()) {} else |_| {}
\\}
\\export fn c() void {
\\ var x: ?i32 = 1234;
\\ while (x) |_| : (bad()) {}
\\}
\\fn bad() anyerror!void {
\\ return error.Bad;
\\}
,