Corrected parsing for incremental arrays. Correctly handle failed declarations. More tests.

This commit is contained in:
Christoffer Lerno
2020-07-25 21:48:05 +02:00
committed by Christoffer Lerno
parent 34c7df9ee1
commit 75dd644e52
9 changed files with 103 additions and 25 deletions

View File

@@ -0,0 +1,7 @@
func void test()
{
int[3] x = { 1, 2, 3 };
int[] z = &x;
z[1];
// z.size();
}

View File

@@ -83,7 +83,7 @@ func void test16()
uint b = 2;
ushort c = 3;
a = a + c;
int c = a + b; // #error: Cannot add 'int' to 'uint'
int g = a + b; // #error: Cannot add 'int' to 'uint'
}
func void test17()

View File

@@ -1,4 +1,4 @@
// #skip
struct Struct
{
int x;
@@ -32,6 +32,6 @@ func void test2(Enum e)
func void test3(Enum e)
{
EnumB h = cast(e as EnumB);
Func i = cast(e as Func);
//EnumB h = cast(e as EnumB);
//Func i = cast(e as Func);
}

View File

@@ -1,38 +1,40 @@
// #skip
i32[+] a;
int[+] a;
a += 10;
public func i32 main() {
public func int main()
{
a += 20; // @error{cannot add values to incremental array in function scope}
return 0;
}
const i32[+] A;
/*
const int[+] A;
A += 10;
A += 20;
A += 30;
*/
i32[+] b;
int[+] b;
func void test1() {
i32[+] d; // @error{incremental arrays not allowed in function scope}
func void test1()
{
int[+] d; // @error{incremental arrays not allowed in function scope}
}
i32[+] c;
int[+] c;
func void test2()
{
b += 10; // @error{cannot add values to incremental array in function scope}
}
i32[+] a = {} // @error{incremental array cannot have initializer}
int[+] x = {}; // @error{incremental array cannot have initializer}
i32 g;
i8[2] h = { 1, 2 }
int g;
char[2] h = { 1, 2 };
g += 10; // @error{'a' is not an incremental array}
@@ -42,13 +44,13 @@ h += 30; // @error{'d' is not an incremental array}
test2 += 20; // @error{'main' is not an incremental array}
i32[+] i;
int[+] i;
i += xyz; // @error{use of undeclared identifier c}
a += test2; // @error{invalid type conversion from 'i32 ()' to 'i32'}
i32[+] k;
int[+] k;
k += 1;
k += 2;
@@ -56,7 +58,7 @@ k += 3;
public func void test3()
{
i32 c = a; // @error{invalid type conversion from 'i32[3]' to 'i32'}
int c = a; // @error{invalid type conversion from 'i32[3]' to 'i32'}
}
struct Point
@@ -67,7 +69,7 @@ struct Point
Point[+] points;
points += { 10, 11 }
points += { 20, main } // @error{invalid type conversion from 'i32 ()' to 'i32'}
points += { 30, 31 }
points += { 10, 11 };
points += { 20, main }; // @error{invalid type conversion from 'i32 ()' to 'i32'}
points += { 30, 31 };

View File

@@ -0,0 +1,64 @@
typedef func int(int) as Func;
typedef func int(Foo*, int) as Func2;
struct Foo
{
int a;
Func callback;
}
func int Foo.func2(Foo* f, int i)
{
return f.a + i;
}
func void test_unknown_member()
{
int a = Foo.b; // #error: No function or member 'Foo.b' found.
}
/*
func void test_regular_member1()
{
int a = Foo.a.sizeof;
int b = Foo.a; // @error{member 'a' cannot be used without instance}
}
func void test_regular_member2()
{
int a = Foo.a(); // @error{member 'a' cannot be used without instance}
}
func void test_function_member1()
{
Func a = Foo.callback; // @error{member 'callback' cannot be used without instance}
}
func void test_function_member2()
{
int a = Foo.callback.sizeof;
int b = Foo.callback(1); // @error{member 'callback' cannot be used without instance}
}
func void test_static_struct_func()
{
Func a = Foo.func1;
int b = Foo.func1(1);
int c = Foo.func1.sizeof;
}
func void test_nonstatic_stuct_func1()
{
Func2 a = Foo.func2;
}
func void test_nonstatic_stuct_func2()
{
int a = Foo.func2.sizeof;
int b = Foo.func2(nil, 2);
}
*/