diff options
Diffstat (limited to 'tests/conformance/5-declarations')
41 files changed, 288 insertions, 0 deletions
diff --git a/tests/conformance/5-declarations/const_chain.zc b/tests/conformance/5-declarations/const_chain.zc new file mode 100644 index 0000000..96ab822 --- /dev/null +++ b/tests/conformance/5-declarations/const_chain.zc @@ -0,0 +1,6 @@ +// expect: 4/ +// spec 5.4 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +const A = 1, B = A + 3; +fn main() { pn(B); return 0; } diff --git a/tests/conformance/5-declarations/const_typed.zc b/tests/conformance/5-declarations/const_typed.zc new file mode 100644 index 0000000..f760da7 --- /dev/null +++ b/tests/conformance/5-declarations/const_typed.zc @@ -0,0 +1,6 @@ +// expect: 3/ +// spec 5.4 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +const int A = 3; +fn main() { pn(A); return 0; } diff --git a/tests/conformance/5-declarations/docs_no_effect.zc b/tests/conformance/5-declarations/docs_no_effect.zc new file mode 100644 index 0000000..32cf1eb --- /dev/null +++ b/tests/conformance/5-declarations/docs_no_effect.zc @@ -0,0 +1,10 @@ +// expect: 3/ +// spec 5.14 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +docs on; +/// three +int f() { return 3; } +docs off; +fn main() { pn(f()); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/embed_missing_file.zc b/tests/conformance/5-declarations/embed_missing_file.zc new file mode 100644 index 0000000..b83276b --- /dev/null +++ b/tests/conformance/5-declarations/embed_missing_file.zc @@ -0,0 +1,7 @@ +// expect error: can't read the file named by embed +// spec 5.11 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +embed "no_such_file_xyz.bin" as d; +fn main() { return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/enhance_wrong_inputs.zc b/tests/conformance/5-declarations/enhance_wrong_inputs.zc new file mode 100644 index 0000000..2ec23e0 --- /dev/null +++ b/tests/conformance/5-declarations/enhance_wrong_inputs.zc @@ -0,0 +1,7 @@ +// expect error: add2: wrong number of inputs +// spec 5.10 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +enhance add2(a, b) vm { + }; +fn main() { pn(add2(1)); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/enum_member_names_earlier_b2.zc b/tests/conformance/5-declarations/enum_member_names_earlier_b2.zc new file mode 100644 index 0000000..a0f82e7 --- /dev/null +++ b/tests/conformance/5-declarations/enum_member_names_earlier_b2.zc @@ -0,0 +1,7 @@ +// expect: 17/ +// spec 2.8 and appendix b.2.2 (bug: rejected) +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +enum { HI = 16, LO = HI + 1 }; +fn main() { pn(LO); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/fn_13th_param_tagged.zc b/tests/conformance/5-declarations/fn_13th_param_tagged.zc new file mode 100644 index 0000000..6aee764 --- /dev/null +++ b/tests/conformance/5-declarations/fn_13th_param_tagged.zc @@ -0,0 +1,7 @@ +// expect error: only the first 12 parameters can be tagged +// spec 5.2.2 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn f(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,.d a13) { return 0; } +fn main() { return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/fn_bare_name_not_declaration.zc b/tests/conformance/5-declarations/fn_bare_name_not_declaration.zc new file mode 100644 index 0000000..4da0bed --- /dev/null +++ b/tests/conformance/5-declarations/fn_bare_name_not_declaration.zc @@ -0,0 +1,7 @@ +// expect error: expected a declaration +// spec 5.2.1 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +f(x) { return x; } +fn main() { return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/fn_call_before_definition.zc b/tests/conformance/5-declarations/fn_call_before_definition.zc new file mode 100644 index 0000000..44904da --- /dev/null +++ b/tests/conformance/5-declarations/fn_call_before_definition.zc @@ -0,0 +1,6 @@ +// expect: 7/ +// spec 5.1.3 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { pn(f()); return 0; } +int f() { return 7; } diff --git a/tests/conformance/5-declarations/fn_falls_off_returns_zero.zc b/tests/conformance/5-declarations/fn_falls_off_returns_zero.zc new file mode 100644 index 0000000..2368c0f --- /dev/null +++ b/tests/conformance/5-declarations/fn_falls_off_returns_zero.zc @@ -0,0 +1,6 @@ +// expect: 0/ +// spec 5.2.3 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int f() { } +fn main() { pn(f()); return 0; } diff --git a/tests/conformance/5-declarations/fn_main_int_return_ignored.zc b/tests/conformance/5-declarations/fn_main_int_return_ignored.zc new file mode 100644 index 0000000..11cbe9c --- /dev/null +++ b/tests/conformance/5-declarations/fn_main_int_return_ignored.zc @@ -0,0 +1,5 @@ +// expect: ok/ +// spec 5.2.5 and 8.1.3 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int main() { rt.put_s("ok"); rt.put_c(10); return 5; } diff --git a/tests/conformance/5-declarations/fn_main_void.zc b/tests/conformance/5-declarations/fn_main_void.zc new file mode 100644 index 0000000..75ddc79 --- /dev/null +++ b/tests/conformance/5-declarations/fn_main_void.zc @@ -0,0 +1,6 @@ +// expect: ok/ +// spec 5.2.5 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +void main() { rt.put_s("ok"); rt.put_c(10); } +// zc0: skip diff --git a/tests/conformance/5-declarations/fn_prototype_after_definition_b4.zc b/tests/conformance/5-declarations/fn_prototype_after_definition_b4.zc new file mode 100644 index 0000000..5b60578 --- /dev/null +++ b/tests/conformance/5-declarations/fn_prototype_after_definition_b4.zc @@ -0,0 +1,8 @@ +// expect: 1/ +// spec 5.2.6 and appendix b.2.4 (bug: definition hidden) +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int f() { return 1; } +int f(); +fn main() { pn(f()); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/fn_prototype_mismatch.zc b/tests/conformance/5-declarations/fn_prototype_mismatch.zc new file mode 100644 index 0000000..f55c95d --- /dev/null +++ b/tests/conformance/5-declarations/fn_prototype_mismatch.zc @@ -0,0 +1,8 @@ +// expect error: f: doesn't match its earlier declaration +// spec 5.2.6 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int f(int a); +int f(int a, int b) { return a; } +fn main() { return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/fn_prototype_named_params.zc b/tests/conformance/5-declarations/fn_prototype_named_params.zc new file mode 100644 index 0000000..6c6cbc0 --- /dev/null +++ b/tests/conformance/5-declarations/fn_prototype_named_params.zc @@ -0,0 +1,7 @@ +// expect: 9/ +// spec 5.2.1 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int sq(int n); +fn main() { pn(sq(3)); return 0; } +int sq(int n) { return n * n; } diff --git a/tests/conformance/5-declarations/fn_prototype_unnamed_params_b13.zc b/tests/conformance/5-declarations/fn_prototype_unnamed_params_b13.zc new file mode 100644 index 0000000..34ba270 --- /dev/null +++ b/tests/conformance/5-declarations/fn_prototype_unnamed_params_b13.zc @@ -0,0 +1,8 @@ +// expect: 4/ +// spec 5.2.1 and appendix b.2.13 (bug: rejected) +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int dbl(int); +fn main() { pn(dbl(2)); return 0; } +int dbl(int n) { return n * 2; } +// zc0: skip diff --git a/tests/conformance/5-declarations/fn_redefined_b3.zc b/tests/conformance/5-declarations/fn_redefined_b3.zc new file mode 100644 index 0000000..3f78173 --- /dev/null +++ b/tests/conformance/5-declarations/fn_redefined_b3.zc @@ -0,0 +1,8 @@ +// expect error: f: is defined twice +// spec 5.2.6 and appendix b.2.3 (bug: accepted silently) +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int f() { return 1; } +int f() { return 2; } +fn main() { pn(f()); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/fn_return_tag_only_u.zc b/tests/conformance/5-declarations/fn_return_tag_only_u.zc new file mode 100644 index 0000000..87ec86b --- /dev/null +++ b/tests/conformance/5-declarations/fn_return_tag_only_u.zc @@ -0,0 +1,7 @@ +// expect error: the only return tag is .u +// spec 5.2.3 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int*.m f() { return 0; } +fn main() { return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/fn_struct_param_rejected.zc b/tests/conformance/5-declarations/fn_struct_param_rejected.zc new file mode 100644 index 0000000..d54f999 --- /dev/null +++ b/tests/conformance/5-declarations/fn_struct_param_rejected.zc @@ -0,0 +1,8 @@ +// expect error: structs and arrays are passed by pointer +// spec 5.2.2 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +struct p { int x; } +int f(p v) { return 0; } +fn main() { return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/fn_typed_mixed_params.zc b/tests/conformance/5-declarations/fn_typed_mixed_params.zc new file mode 100644 index 0000000..c0658ee --- /dev/null +++ b/tests/conformance/5-declarations/fn_typed_mixed_params.zc @@ -0,0 +1,6 @@ +// expect: 5/ +// spec 5.2.1 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn f(int a, b) { return a + b; } +fn main() { pn(f(2, 3)); return 0; } diff --git a/tests/conformance/5-declarations/fn_u_falls_off.zc b/tests/conformance/5-declarations/fn_u_falls_off.zc new file mode 100644 index 0000000..3ab6194 --- /dev/null +++ b/tests/conformance/5-declarations/fn_u_falls_off.zc @@ -0,0 +1,7 @@ +// expect error: a function returning .u has to end with a return +// spec 5.2.3 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +.u f(int k) { if (k) return rt.new(2); } +fn main() { return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/global_call_init_rejected.zc b/tests/conformance/5-declarations/global_call_init_rejected.zc new file mode 100644 index 0000000..b4b1301 --- /dev/null +++ b/tests/conformance/5-declarations/global_call_init_rejected.zc @@ -0,0 +1,8 @@ +// expect error: expected ';', found '(' +// spec 5.3.2 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int f() { return 1; } +int a = f(); +fn main() { return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/global_const_expr_init.zc b/tests/conformance/5-declarations/global_const_expr_init.zc new file mode 100644 index 0000000..8a9d30b --- /dev/null +++ b/tests/conformance/5-declarations/global_const_expr_init.zc @@ -0,0 +1,7 @@ +// expect: 4/ +// spec 5.3.2 and 3.14.1 (left to right: ((1+2)*2)-2) +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int g = 1 + 2 * 2 - 2; +fn main() { pn(g); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/global_float_init_b7.zc b/tests/conformance/5-declarations/global_float_init_b7.zc new file mode 100644 index 0000000..14d5204 --- /dev/null +++ b/tests/conformance/5-declarations/global_float_init_b7.zc @@ -0,0 +1,7 @@ +// expect: 1/ +// spec 5.3.2 and appendix b.2.7 (bug: rejected) +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +float g = 1.5; +fn main() { pn(g * 2.0 == 3.0); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/global_names_global_b8.zc b/tests/conformance/5-declarations/global_names_global_b8.zc new file mode 100644 index 0000000..7d678eb --- /dev/null +++ b/tests/conformance/5-declarations/global_names_global_b8.zc @@ -0,0 +1,7 @@ +// expect: 1/ +// spec 5.3.2 and 3.14.2: a global named in an initializer is its address (appendix b.2.8 calls this a bug) +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int a = 5; int b = a + 1; +fn main() { pn(b == (int)&a + 1); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/global_tagged_rejected.zc b/tests/conformance/5-declarations/global_tagged_rejected.zc new file mode 100644 index 0000000..3386ae4 --- /dev/null +++ b/tests/conformance/5-declarations/global_tagged_rejected.zc @@ -0,0 +1,7 @@ +// expect error: tags go on locals and parameters, not globals +// spec 5.3.3 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int*.m g; +fn main() { return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/global_word_string.zc b/tests/conformance/5-declarations/global_word_string.zc new file mode 100644 index 0000000..3a5ba48 --- /dev/null +++ b/tests/conformance/5-declarations/global_word_string.zc @@ -0,0 +1,7 @@ +// expect: hi/ +// spec 5.3.2 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +char* s = "hi"; +fn main() { rt.put_s(s); rt.put_c(10); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/global_zero_initialised.zc b/tests/conformance/5-declarations/global_zero_initialised.zc new file mode 100644 index 0000000..6f1665d --- /dev/null +++ b/tests/conformance/5-declarations/global_zero_initialised.zc @@ -0,0 +1,7 @@ +// expect: 0/0/ +// spec 5.3.1 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int g; int[4] buf; +fn main() { pn(g); pn(buf[3]); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/include_in_function_b9.zc b/tests/conformance/5-declarations/include_in_function_b9.zc new file mode 100644 index 0000000..cccaea5 --- /dev/null +++ b/tests/conformance/5-declarations/include_in_function_b9.zc @@ -0,0 +1,6 @@ +// expect error: include +// spec 5.12.7 and appendix b.2.9: expected an error saying include is top level only +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { include std; return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/include_rt_required.zc b/tests/conformance/5-declarations/include_rt_required.zc new file mode 100644 index 0000000..e897e97 --- /dev/null +++ b/tests/conformance/5-declarations/include_rt_required.zc @@ -0,0 +1,4 @@ +// expect error: module access requires `include rt;` +// spec 5.12.4 and 8.1.1 +fn main() { rt.put_c(65); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/include_twice_compiled_once.zc b/tests/conformance/5-declarations/include_twice_compiled_once.zc new file mode 100644 index 0000000..153f66e --- /dev/null +++ b/tests/conformance/5-declarations/include_twice_compiled_once.zc @@ -0,0 +1,8 @@ +// expect: ok/ +// spec 5.12.8 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +include std; +include std; +fn main() { rt.put_s("ok"); rt.put_c(10); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/namespace_main_runs.zc b/tests/conformance/5-declarations/namespace_main_runs.zc new file mode 100644 index 0000000..8a62291 --- /dev/null +++ b/tests/conformance/5-declarations/namespace_main_runs.zc @@ -0,0 +1,7 @@ +// expect: 1/ +// spec 8.1.2: main in a namespaced file runs +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +namespace foo; +fn main() { pn(1); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/struct_constant_duplicate.zc b/tests/conformance/5-declarations/struct_constant_duplicate.zc new file mode 100644 index 0000000..df14af9 --- /dev/null +++ b/tests/conformance/5-declarations/struct_constant_duplicate.zc @@ -0,0 +1,7 @@ +// expect error: MAX: is defined twice in this struct +// spec 5.5.1 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +struct s { const MAX = 1; const MAX = 2; } +fn main() { return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/struct_constant_outside_and_inside.zc b/tests/conformance/5-declarations/struct_constant_outside_and_inside.zc new file mode 100644 index 0000000..79686f8 --- /dev/null +++ b/tests/conformance/5-declarations/struct_constant_outside_and_inside.zc @@ -0,0 +1,7 @@ +// expect: 24/25/ +// spec 5.5.1 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +struct s { int x; const MAX = 24; fn m() { return MAX + 1; } } +fn main() { s* p = rt.new(s); pn(s.MAX); pn(p.m()); rt.free(p); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/struct_field_wins_over_method.zc b/tests/conformance/5-declarations/struct_field_wins_over_method.zc new file mode 100644 index 0000000..14bf08b --- /dev/null +++ b/tests/conformance/5-declarations/struct_field_wins_over_method.zc @@ -0,0 +1,8 @@ +// expect: 9/ +// spec 5.5.4 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int t9() { return 9; } +struct s { int x; let m; fn m() { return 1; } } +fn main() { s* p = rt.new(s); p.m = t9; pn(p.m()); rt.free(p); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/struct_method_calls_later.zc b/tests/conformance/5-declarations/struct_method_calls_later.zc new file mode 100644 index 0000000..5230f81 --- /dev/null +++ b/tests/conformance/5-declarations/struct_method_calls_later.zc @@ -0,0 +1,7 @@ +// expect: 3/ +// spec 5.5.2 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +struct s { int x; fn a() { return this.b(); } fn b() { return this.x; } } +fn main() { s* p = rt.new(s); p.x = 3; pn(p.a()); rt.free(p); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/struct_static_beats_toplevel.zc b/tests/conformance/5-declarations/struct_static_beats_toplevel.zc new file mode 100644 index 0000000..ee63428 --- /dev/null +++ b/tests/conformance/5-declarations/struct_static_beats_toplevel.zc @@ -0,0 +1,8 @@ +// expect: 2/ +// spec 5.5.5 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn two() { return 99; } +struct s { int x; static fn two() { return 2; } static fn get() { return two(); } } +fn main() { pn(s.get()); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/struct_static_call.zc b/tests/conformance/5-declarations/struct_static_call.zc new file mode 100644 index 0000000..e2b4fe8 --- /dev/null +++ b/tests/conformance/5-declarations/struct_static_call.zc @@ -0,0 +1,7 @@ +// expect: 6/6/ +// spec 5.5.5 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +struct s { int x; static fn two() { return 2; } static fn six() { return two() * 3; } } +fn main() { pn(s.six()); pn(s.two() * 3); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/struct_static_misspelled.zc b/tests/conformance/5-declarations/struct_static_misspelled.zc new file mode 100644 index 0000000..9986fde --- /dev/null +++ b/tests/conformance/5-declarations/struct_static_misspelled.zc @@ -0,0 +1,7 @@ +// expect error: MAXX: is not a static function of this struct; did you mean 'MAX'? +// spec 5.5.6 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +struct s { int x; const MAX = 1; } +fn main() { pn(s.MAXX); return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/struct_this_declared.zc b/tests/conformance/5-declarations/struct_this_declared.zc new file mode 100644 index 0000000..88c67e5 --- /dev/null +++ b/tests/conformance/5-declarations/struct_this_declared.zc @@ -0,0 +1,7 @@ +// expect error: this is implicit and cannot be declared as a method parameter +// spec 5.5.2 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +struct s { int x; fn m(s* this) { return 0; } } +fn main() { return 0; } +// zc0: skip diff --git a/tests/conformance/5-declarations/type_alias.zc b/tests/conformance/5-declarations/type_alias.zc new file mode 100644 index 0000000..98f7f06 --- /dev/null +++ b/tests/conformance/5-declarations/type_alias.zc @@ -0,0 +1,8 @@ +// expect: 5/ +// spec 5.6 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +type num = int; +num f(num a) { return a + 1; } +fn main() { pn(f(4)); return 0; } +// zc0: skip |
