-
Notifications
You must be signed in to change notification settings - Fork 518
/
inline_macros
973 lines (727 loc) · 24.8 KB
/
inline_macros
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
//! > Test bad consteval_int! macros
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function
fn foo() {}
//! > function_name
foo
//! > module_code
const a: felt252 = consteval_int!(func_call(24));
const b: felt252 = consteval_int!('some string');
const c: felt252 = consteval_int!(*24);
const d: felt252 = consteval_int!(~24);
const e: felt252 = consteval_int!(234 < 5);
const e: felt252 = consteval_int![4 + 5];
const f: felt252 = consteval_int!{4 + 5};
const out_of_range: u8 = consteval_int!(120 + 160);
//! > expected_diagnostics
error: The name `e` is defined multiple times.
--> lib.cairo:11:7
const e: felt252 = consteval_int![4 + 5];
^
error: Plugin diagnostic: Unsupported expression in consteval_int macro
--> lib.cairo:1:35
const a: felt252 = consteval_int!(func_call(24));
^***********^
error: Plugin diagnostic: Unsupported expression in consteval_int macro
--> lib.cairo:3:35
const b: felt252 = consteval_int!('some string');
^***********^
error: Plugin diagnostic: Unsupported unary operator in consteval_int macro
--> lib.cairo:5:35
const c: felt252 = consteval_int!(*24);
^*^
error: Plugin diagnostic: Unsupported unary operator in consteval_int macro
--> lib.cairo:7:35
const d: felt252 = consteval_int!(~24);
^*^
error: Plugin diagnostic: Unsupported binary operator in consteval_int macro
--> lib.cairo:9:35
const e: felt252 = consteval_int!(234 < 5);
^*****^
error: Plugin diagnostic: Macro `consteval_int` does not support this bracket type.
--> lib.cairo:11:34
const e: felt252 = consteval_int![4 + 5];
^
error: Plugin diagnostic: Macro `consteval_int` does not support this bracket type.
--> lib.cairo:13:34
const f: felt252 = consteval_int!{4 + 5};
^
error: The value does not fit within the range of type core::integer::u8.
--> lib.cairo:15:26
const out_of_range: u8 = consteval_int!(120 + 160);
^***********************^
//! > ==========================================================================
//! > Test bad array! macros
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function
fn foo() {
let _x = array!(0);
let _x = array![0_felt252, 1_u8];
}
//! > function_name
foo
//! > module_code
//! > expected_diagnostics
error: Plugin diagnostic: Macro `array` does not support this bracket type.
--> lib.cairo:2:20
let _x = array!(0);
^
error: Unexpected expression type. Expected: "core::felt252", found: "core::integer::u8".
--> lib.cairo:3:32
let _x = array![0_felt252, 1_u8];
^**^
error: Unexpected argument type. Expected: "core::felt252", found: "core::integer::u8".
--> lib.cairo:3:32
let _x = array![0_felt252, 1_u8];
^**^
//! > ==========================================================================
//! > Test bad write! macros
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function
fn foo() {
let mut f: core::fmt::Formatter = Default::default();
let ba: ByteArray = "hello";
// Bad brackets.
write![f, "{}", ba];
// No params.
write!();
// One param.
write!(f);
// No formatter.
write!("{}", ba);
// No format string.
write!(f, ba);
// Non existing inline argument.
write!(f, "{non_existing}").unwrap();
// Non existing provide argument.
write!(f, "{}", non_existing).unwrap();
// Too many arguments.
write!(f, "{}", ba, 1);
// Too few arguments.
write!(f, "{}{}", ba);
// Out of range positional argument.
write!(f, "{2}{1}{0}", ba, 1);
// Unused arguments.
write!(f, "{2}{0}", ba, 2, 1, 4);
// --- Bad placeholder arguments.
// Bad parameter names.
write!(f, "{3a}");
write!(f, "{a-b}");
write!(f, "{a b}");
write!(f, "{?}");
write!(f, "{x|}");
// Bad formatting specifications.
write!(f, "{::x}");
write!(f, "{:x:y}");
write!(f, "{:x ?}");
write!(f, "{:??}");
// Non terminated `{`.
write!(f, "{");
write!(f, "{x");
}
//! > function_name
foo
//! > module_code
//! > expected_diagnostics
error: Plugin diagnostic: Macro `write` does not support this bracket type.
--> lib.cairo:6:11
write![f, "{}", ba];
^
error: Plugin diagnostic: Macro expected formatter argument.
--> lib.cairo:9:11
write!();
^
error: Plugin diagnostic: Macro expected format string argument.
--> lib.cairo:12:11
write!(f);
^
error: Plugin diagnostic: Formatter argument must not be a string literal.
--> lib.cairo:15:12
write!("{}", ba);
^**^
error: Plugin diagnostic: Format string argument must be a string literal.
--> lib.cairo:18:15
write!(f, ba);
^^
error: Identifier not found.
--> lib.cairo:21:17
write!(f, "{non_existing}").unwrap();
^**********^
error: Identifier not found.
--> lib.cairo:24:21
write!(f, "{}", non_existing).unwrap();
^**********^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:27:25
write!(f, "{}", ba, 1);
^
error: Plugin diagnostic: 2 positional arguments in format string, but only 1 arguments.
--> lib.cairo:30:15
write!(f, "{}{}", ba);
^****^
error: Plugin diagnostic: Invalid reference to positional argument 2 (there are 2 arguments).
--> lib.cairo:33:15
write!(f, "{2}{1}{0}", ba, 1);
^*********^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:36:29
write!(f, "{2}{0}", ba, 2, 1, 4);
^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:36:35
write!(f, "{2}{0}", ba, 2, 1, 4);
^
error: Plugin diagnostic: Invalid format string: Invalid parameter name.
--> lib.cairo:41:15
write!(f, "{3a}");
^****^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: parameter name can only contain alphanumeric characters and '_'. You may be missing a ':'.
--> lib.cairo:42:15
write!(f, "{a-b}");
^*****^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: parameter name can only contain alphanumeric characters and '_'. You may be missing a ':'.
--> lib.cairo:43:15
write!(f, "{a b}");
^*****^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: parameter name can only contain alphanumeric characters and '_'. You may be missing a ':'.
--> lib.cairo:44:15
write!(f, "{?}");
^***^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: parameter name can only contain alphanumeric characters and '_'. You may be missing a ':'.
--> lib.cairo:45:15
write!(f, "{x|}");
^****^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: the formatting specification part (after the ':') can not contain a ':'.
--> lib.cairo:48:15
write!(f, "{::x}");
^*****^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: the formatting specification part (after the ':') can not contain a ':'.
--> lib.cairo:49:15
write!(f, "{:x:y}");
^******^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: the formatting specification part (after the ':') can only contain graphic characters.
--> lib.cairo:50:15
write!(f, "{:x ?}");
^******^
error: Plugin diagnostic: Invalid format string: Unsupported formatting trait: only `Display` and `Debug` are supported.
--> lib.cairo:51:15
write!(f, "{:??}");
^*****^
error: Plugin diagnostic: Invalid format string: Unterminated placeholder: no matching '}' for '{'.
--> lib.cairo:54:15
write!(f, "{");
^*^
error: Plugin diagnostic: Invalid format string: Unterminated placeholder: no matching '}' for '{'.
--> lib.cairo:55:15
write!(f, "{x");
^**^
warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
--> lib.cairo:3:9
let ba: ByteArray = "hello";
^^
error: Type annotations needed. Failed to infer ?3.
--> lib.cairo:21:17
write!(f, "{non_existing}").unwrap();
^**********^
//! > ==========================================================================
//! > Test bad writeln! macros
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function
fn foo() {
let mut f: core::fmt::Formatter = Default::default();
let ba: ByteArray = "hello";
// Bad brackets.
writeln![f, "{}", ba];
// No params.
writeln!();
// One param.
writeln!(f);
// No formatter.
writeln!("{}", ba);
// No format string.
writeln!(f, ba);
// Non existing inline argument.
writeln!(f, "{non_existing}").unwrap();
// Non existing provide argument.
writeln!(f, "{}", non_existing).unwrap();
// Too many arguments.
writeln!(f, "{}", ba, 1);
// Too few arguments.
writeln!(f, "{}{}", ba);
// Out of range positional argument.
writeln!(f, "{2}{1}{0}", ba, 1);
// Unused arguments.
writeln!(f, "{2}{0}", ba, 2, 1, 4);
// --- Bad placeholder arguments.
// Bad parameter names.
writeln!(f, "{3a}");
writeln!(f, "{a-b}");
writeln!(f, "{a b}");
writeln!(f, "{?}");
writeln!(f, "{x|}");
// Bad formatting specifications.
writeln!(f, "{::x}");
writeln!(f, "{:x:y}");
writeln!(f, "{:x ?}");
writeln!(f, "{:??}");
// Non terminated `{`.
writeln!(f, "{");
writeln!(f, "{x");
}
//! > function_name
foo
//! > module_code
//! > expected_diagnostics
error: Plugin diagnostic: Macro `writeln` does not support this bracket type.
--> lib.cairo:6:13
writeln![f, "{}", ba];
^
error: Plugin diagnostic: Macro expected formatter argument.
--> lib.cairo:9:13
writeln!();
^
error: Plugin diagnostic: Macro expected format string argument.
--> lib.cairo:12:13
writeln!(f);
^
error: Plugin diagnostic: Formatter argument must not be a string literal.
--> lib.cairo:15:14
writeln!("{}", ba);
^**^
error: Plugin diagnostic: Format string argument must be a string literal.
--> lib.cairo:18:17
writeln!(f, ba);
^^
error: Identifier not found.
--> lib.cairo:21:19
writeln!(f, "{non_existing}").unwrap();
^**********^
error: Identifier not found.
--> lib.cairo:24:23
writeln!(f, "{}", non_existing).unwrap();
^**********^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:27:27
writeln!(f, "{}", ba, 1);
^
error: Plugin diagnostic: 2 positional arguments in format string, but only 1 arguments.
--> lib.cairo:30:17
writeln!(f, "{}{}", ba);
^****^
error: Plugin diagnostic: Invalid reference to positional argument 2 (there are 2 arguments).
--> lib.cairo:33:17
writeln!(f, "{2}{1}{0}", ba, 1);
^*********^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:36:31
writeln!(f, "{2}{0}", ba, 2, 1, 4);
^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:36:37
writeln!(f, "{2}{0}", ba, 2, 1, 4);
^
error: Plugin diagnostic: Invalid format string: Invalid parameter name.
--> lib.cairo:41:17
writeln!(f, "{3a}");
^****^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: parameter name can only contain alphanumeric characters and '_'. You may be missing a ':'.
--> lib.cairo:42:17
writeln!(f, "{a-b}");
^*****^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: parameter name can only contain alphanumeric characters and '_'. You may be missing a ':'.
--> lib.cairo:43:17
writeln!(f, "{a b}");
^*****^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: parameter name can only contain alphanumeric characters and '_'. You may be missing a ':'.
--> lib.cairo:44:17
writeln!(f, "{?}");
^***^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: parameter name can only contain alphanumeric characters and '_'. You may be missing a ':'.
--> lib.cairo:45:17
writeln!(f, "{x|}");
^****^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: the formatting specification part (after the ':') can not contain a ':'.
--> lib.cairo:48:17
writeln!(f, "{::x}");
^*****^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: the formatting specification part (after the ':') can not contain a ':'.
--> lib.cairo:49:17
writeln!(f, "{:x:y}");
^******^
error: Plugin diagnostic: Invalid format string: Unexpected character in placeholder: the formatting specification part (after the ':') can only contain graphic characters.
--> lib.cairo:50:17
writeln!(f, "{:x ?}");
^******^
error: Plugin diagnostic: Invalid format string: Unsupported formatting trait: only `Display` and `Debug` are supported.
--> lib.cairo:51:17
writeln!(f, "{:??}");
^*****^
error: Plugin diagnostic: Invalid format string: Unterminated placeholder: no matching '}' for '{'.
--> lib.cairo:54:17
writeln!(f, "{");
^*^
error: Plugin diagnostic: Invalid format string: Unterminated placeholder: no matching '}' for '{'.
--> lib.cairo:55:17
writeln!(f, "{x");
^**^
warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
--> lib.cairo:3:9
let ba: ByteArray = "hello";
^^
error: Type annotations needed. Failed to infer ?3.
--> lib.cairo:21:19
writeln!(f, "{non_existing}").unwrap();
^**********^
//! > ==========================================================================
//! > Test bad format! macros
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function
fn foo() {
let ba: ByteArray = "hello";
// Bad brackets. TODO(orizi): Improve diagnostic to not include "write".
format!["{}", ba];
// No params.
format!();
// No format string.
format!(ba);
// Non existing inline argument.
format!("{non_existing}");
// Non existing provide argument.
format!("{}", non_existing);
// Too many arguments.
format!("{}", ba, 1);
// Too few arguments.
format!("{}{}", ba);
// Out of range positional argument.
format!("{2}{1}{0}", ba, 1);
// Unused arguments.
format!("{2}{0}", ba, 2, 1);
}
//! > function_name
foo
//! > module_code
//! > expected_diagnostics
error: Plugin diagnostic: Macro `write` does not support this bracket type.
--> lib.cairo:5:12
format!["{}", ba];
^
error: Plugin diagnostic: Macro expected format string argument.
--> lib.cairo:8:12
format!();
^
error: Plugin diagnostic: Format string argument must be a string literal.
--> lib.cairo:11:13
format!(ba);
^^
error: Identifier not found.
--> lib.cairo:14:15
format!("{non_existing}");
^**********^
error: Identifier not found.
--> lib.cairo:17:19
format!("{}", non_existing);
^**********^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:20:23
format!("{}", ba, 1);
^
error: Plugin diagnostic: 2 positional arguments in format string, but only 1 arguments.
--> lib.cairo:23:13
format!("{}{}", ba);
^****^
error: Plugin diagnostic: Invalid reference to positional argument 2 (there are 2 arguments).
--> lib.cairo:26:13
format!("{2}{1}{0}", ba, 1);
^*********^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:29:27
format!("{2}{0}", ba, 2, 1);
^
warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
--> lib.cairo:2:9
let ba: ByteArray = "hello";
^^
error: Type annotations needed. Failed to infer ?6.
--> lib.cairo:14:15
format!("{non_existing}");
^**********^
//! > ==========================================================================
//! > Test bad print! macros
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function
fn foo() {
let ba: ByteArray = "hello";
// Bad brackets. TODO(orizi): Improve diagnostic to not include "write".
print!["{}", ba];
// No params.
print!();
// No format string.
print!(ba);
// Non existing inline argument.
print!("{non_existing}");
// Non existing provide argument.
print!("{}", non_existing);
// Too many arguments.
print!("{}", ba, 1);
// Too few arguments.
print!("{}{}", ba);
// Out of range positional argument.
print!("{2}{1}{0}", ba, 1);
// Unused arguments.
print!("{2}{0}", ba, 2, 1);
// Missing parens.
print!;
}
//! > function_name
foo
//! > module_code
//! > expected_diagnostics
error: Missing tokens. Expected an argument list wrapped in either parentheses, brackets, or braces.
--> lib.cairo:32:11
print!;
^
error: Plugin diagnostic: Macro `write` does not support this bracket type.
--> lib.cairo:5:11
print!["{}", ba];
^
error: Plugin diagnostic: Macro expected format string argument.
--> lib.cairo:8:11
print!();
^
error: Plugin diagnostic: Format string argument must be a string literal.
--> lib.cairo:11:12
print!(ba);
^^
error: Identifier not found.
--> lib.cairo:14:14
print!("{non_existing}");
^**********^
error: Identifier not found.
--> lib.cairo:17:18
print!("{}", non_existing);
^**********^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:20:22
print!("{}", ba, 1);
^
error: Plugin diagnostic: 2 positional arguments in format string, but only 1 arguments.
--> lib.cairo:23:12
print!("{}{}", ba);
^****^
error: Plugin diagnostic: Invalid reference to positional argument 2 (there are 2 arguments).
--> lib.cairo:26:12
print!("{2}{1}{0}", ba, 1);
^*********^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:29:26
print!("{2}{0}", ba, 2, 1);
^
error: Plugin diagnostic: Macro `write` does not support this bracket type.
--> lib.cairo:32:11
print!;
^
error: Wrong number of arguments. Expected 1, found: 2
--> lib.cairo[print_macro]:3:5
core::result::ResultTrait::<(), core::fmt::Error>::unwrap(
^********************************************************^
warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
--> lib.cairo:2:9
let ba: ByteArray = "hello";
^^
error: Type annotations needed. Failed to infer ?9.
--> lib.cairo:14:14
print!("{non_existing}");
^**********^
//! > ==========================================================================
//! > Test bad println! macros
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function
fn foo() {
let ba: ByteArray = "hello";
// Bad brackets. TODO(orizi): Improve diagnostic to not include "write".
println!["{}", ba];
// No params.
println!();
// No format string.
println!(ba);
// Non existing inline argument.
println!("{non_existing}");
// Non existing provide argument.
println!("{}", non_existing);
// Too many arguments.
println!("{}", ba, 1);
// Too few arguments.
println!("{}{}", ba);
// Out of range positional argument.
println!("{2}{1}{0}", ba, 1);
// Unused arguments.
println!("{2}{0}", ba, 2, 1);
// Missing parens.
println!;
}
//! > function_name
foo
//! > module_code
//! > expected_diagnostics
error: Missing tokens. Expected an argument list wrapped in either parentheses, brackets, or braces.
--> lib.cairo:32:13
println!;
^
error: Plugin diagnostic: Macro `writeln` does not support this bracket type.
--> lib.cairo:5:13
println!["{}", ba];
^
error: Plugin diagnostic: Macro expected format string argument.
--> lib.cairo:8:13
println!();
^
error: Plugin diagnostic: Format string argument must be a string literal.
--> lib.cairo:11:14
println!(ba);
^^
error: Identifier not found.
--> lib.cairo:14:16
println!("{non_existing}");
^**********^
error: Identifier not found.
--> lib.cairo:17:20
println!("{}", non_existing);
^**********^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:20:24
println!("{}", ba, 1);
^
error: Plugin diagnostic: 2 positional arguments in format string, but only 1 arguments.
--> lib.cairo:23:14
println!("{}{}", ba);
^****^
error: Plugin diagnostic: Invalid reference to positional argument 2 (there are 2 arguments).
--> lib.cairo:26:14
println!("{2}{1}{0}", ba, 1);
^*********^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:29:28
println!("{2}{0}", ba, 2, 1);
^
error: Plugin diagnostic: Macro `writeln` does not support this bracket type.
--> lib.cairo:32:13
println!;
^
error: Wrong number of arguments. Expected 1, found: 2
--> lib.cairo[println_macro]:3:5
core::result::ResultTrait::<(), core::fmt::Error>::unwrap(
^********************************************************^
warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
--> lib.cairo:2:9
let ba: ByteArray = "hello";
^^
error: Type annotations needed. Failed to infer ?9.
--> lib.cairo:14:16
println!("{non_existing}");
^**********^
//! > ==========================================================================
//! > Test bad panic! macros
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function
fn foo() {
let ba: ByteArray = "hello";
// Bad brackets. TODO(orizi): Improve diagnostic to not include "write".
panic!["{}", ba];
// No params.
panic!();
// No format string.
panic!(ba);
// Non existing inline argument.
panic!("{non_existing}");
// Non existing provide argument.
panic!("{}", non_existing);
// Too many arguments.
panic!("{}", ba, 1);
// Too few arguments.
panic!("{}{}", ba);
// Out of range positional argument.
panic!("{2}{1}{0}", ba, 1);
// Unused arguments.
panic!("{2}{0}", ba, 2, 1);
}
//! > function_name
foo
//! > module_code
//! > expected_diagnostics
error: Plugin diagnostic: Macro `panic` does not support this bracket type.
--> lib.cairo:5:11
panic!["{}", ba];
^
error: Plugin diagnostic: Format string argument must be a string literal.
--> lib.cairo:11:12
panic!(ba);
^^
error: Identifier not found.
--> lib.cairo:14:14
panic!("{non_existing}");
^**********^
error: Identifier not found.
--> lib.cairo:17:18
panic!("{}", non_existing);
^**********^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:20:22
panic!("{}", ba, 1);
^
error: Plugin diagnostic: 2 positional arguments in format string, but only 1 arguments.
--> lib.cairo:23:12
panic!("{}{}", ba);
^****^
error: Plugin diagnostic: Invalid reference to positional argument 2 (there are 2 arguments).
--> lib.cairo:26:12
panic!("{2}{1}{0}", ba, 1);
^*********^
error: Plugin diagnostic: Unused argument.
--> lib.cairo:29:26
panic!("{2}{0}", ba, 2, 1);
^
warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`.
--> lib.cairo:2:9
let ba: ByteArray = "hello";
^^
error: Type annotations needed. Failed to infer ?7.
--> lib.cairo:14:14
panic!("{non_existing}");
^**********^
//! > ==========================================================================
//! > Test unknown macro
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function
fn foo() {
let _x = foo!(0);
}
//! > function_name
foo
//! > module_code
//! > expected_diagnostics
error: Inline macro `foo` not found.
--> lib.cairo:2:14
let _x = foo!(0);
^*****^
//! > ==========================================================================
//! > Test comment affects macro name
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: false)
//! > function
fn foo() {
// This comment should not appear in the macro name
array![0_felt252];
}
//! > function_name
foo
//! > module_code
//! > expected_diagnostics