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:
Christoffer Lerno
2025-04-18 17:19:04 +02:00
parent ba10c8953d
commit 946c167bf1
13 changed files with 101 additions and 91 deletions

View 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;
}

View File

@@ -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()

View 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;
}

View 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});
}

View File

@@ -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});
}