mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Improve error for default args #2096. Deprecated old inference with slice copy. Copying must now ensure a slicing operator at the end of the right hand side: foo[1..2] = bar[..] rather than the old foo[1..2] = bar. The old behaviour can be mostly retained with --use-old-slice-copy).
This commit is contained in:
11
test/test_suite/expressions/bad_number_args_2096.c3
Normal file
11
test/test_suite/expressions/bad_number_args_2096.c3
Normal file
@@ -0,0 +1,11 @@
|
||||
fn void foo(int a, int b, bool c = false) {}
|
||||
fn void foo2(int a, int b, bool c) {}
|
||||
|
||||
fn int main()
|
||||
{
|
||||
foo(2); // #error: 1-2 additional arguments were expected
|
||||
foo2(2);// #error: 2 more arguments
|
||||
foo(); // #error: expects 2-3 parameters
|
||||
foo2(); // #error: expects 3 parameter(s)
|
||||
return 0;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ fn void multiple(int x, int y) {}
|
||||
|
||||
fn void f()
|
||||
{
|
||||
multiple(1); // #error: Expected 1 more argument after this one
|
||||
multiple(1); // #error:1 more argument was expected after this one
|
||||
}
|
||||
|
||||
fn void g()
|
||||
|
||||
16
test/test_suite/slices/slice_assign_designated_2095.c3
Normal file
16
test/test_suite/slices/slice_assign_designated_2095.c3
Normal file
@@ -0,0 +1,16 @@
|
||||
module test;
|
||||
|
||||
struct Struct
|
||||
{
|
||||
int field;
|
||||
}
|
||||
|
||||
fn int main()
|
||||
{
|
||||
Struct[4] arr;
|
||||
|
||||
arr[1] = {.field = 1};
|
||||
arr[1..2] = {1};
|
||||
arr[1..2] = {.field = 1};
|
||||
return 0;
|
||||
}
|
||||
7
test/test_suite/slices/slice_scalar.c3
Normal file
7
test/test_suite/slices/slice_scalar.c3
Normal file
@@ -0,0 +1,7 @@
|
||||
fn void assign_slice()
|
||||
{
|
||||
int[8] a;
|
||||
a[2..3] = { 1, 2 }; // #error: Maybe you wanted to do a slice copy
|
||||
a[5..7] = 5;
|
||||
assert(a == (int[8]){ 0, 0, 1, 2, 0, 5, 5, 5});
|
||||
}
|
||||
@@ -3,7 +3,7 @@ module slice_assign @test;
|
||||
fn void assign_slice()
|
||||
{
|
||||
int[8] a;
|
||||
a[2..3] = { 1, 2 };
|
||||
a[2..3] = { 1, 2 }[..];
|
||||
a[5..7] = 5;
|
||||
assert(a == (int[8]){ 0, 0, 1, 2, 0, 5, 5, 5});
|
||||
}
|
||||
Reference in New Issue
Block a user