[fine] Many test improvements, error improvements

- Check for more error conditions
- Move to more definitive error assertions
- Simpler error messages in some cases
- Test more conditions more thoroughly, revisit old tests
This commit is contained in:
John Doty 2024-01-21 08:14:42 -08:00
parent d0b74db715
commit 5f0a0b3268
20 changed files with 186 additions and 118 deletions

View file

@ -298,7 +298,7 @@ fn assert_errors(tree: &SyntaxTree, lines: &Lines, expected_errors: Vec<&str>) {
None,
expected_errors,
errors,
"expected no errors"
"expected error messages to match"
);
}

View file

@ -14,7 +14,7 @@ fun wrong() {
}
// @expect-errors:
// | 7:4: cannot assign a value of type `string` to type `f64`
// | 8:4: cannot assign a value of type `f64` to type `string`
// | 11:4: cannot assign a value of type `f64` to type `string`
// | 7:4: cannot assign a value of type 'string' to type 'f64'
// | 8:4: cannot assign a value of type 'f64' to type 'string'
// | 11:4: cannot assign a value of type 'f64' to type 'string'
// | 13:2: cannot assign a new value to a function declaration

View file

@ -0,0 +1,8 @@
class Foo {}
fun test() -> f64 {
Foo + 23
}
// @expect-errors:
// | 4:2: Foo is a class, not a value (did you mean to create a new instance with 'new'?)

View file

@ -3,6 +3,5 @@ class Foo {
x: f64;
}
// @ignore
// @expect-errors:
// asdfadsf
// | 3:2: duplicate definition of field 'x'

View file

@ -1,5 +1,4 @@
fun something(x: f64, x: f64) {}
// @ignore
// @expect-errors:
// asdfadsf
// | 1:22: duplicate definition of parameter 'x'

View file

@ -0,0 +1,16 @@
fun nested() {
fun foo() {}
fun foo() {}
;
}
fun nested() {}
class Bar {}
class Bar {}
// @expect-errors:
// | 3:2: duplicate definition of function 'foo'
// | 8:0: duplicate definition of function 'nested'
// | 11:0: duplicate definition of class 'Bar'

View file

@ -1,2 +1,4 @@
if true { "blarg" } else { 23 }
// @type-error: 0 the type of the `then` branch (string) must match the type of the `else` branch (f64)
// @expect-errors:
// | 1:0: the type of the 'then' branch ('string') must match the type of the 'else' branch ('f64')

View file

@ -1,2 +1,4 @@
if (if false { true }) { 32 } else { 23 }
// @type-error: 4 the type of the `then` branch (bool) must match the type of the `else` branch (())
// @expect-errors:
// | 1:4: the type of the 'then' branch ('bool') must match the type of the 'else' branch ('()')

View file

@ -0,0 +1,12 @@
{
// This is a block-local declaration; it should *not* appear in the global
// environment.
let y = 23;
}
fun foo() -> f64 {
y + 3
}
// @expect-errors:
// | 8:2: cannot find value y here

View file

@ -5,4 +5,5 @@ fun test() -> f64 {
23.0
}
// @check-error: callers of this function expect a value of type `f64` but this statement returns a value of type `string`
// @expect-errors:
// | 3:4: callers of this function expect a value of type 'f64' but this statement returns a value of type 'string'

View file

@ -2,4 +2,4 @@ fun test() -> bool {
32
}
// @check-error: the body of this function yields a value of type `f64`, but callers expect this function to produce a `bool`
// @check-error: the body of this function yields a value of type 'f64', but callers expect this function to produce a 'bool'

View file

@ -6,6 +6,6 @@ fun test() {
generic_add(10, 10)
}
// @ignore
// @ignore Feature is undesigned, this is tentative garbage
// @no-errors
// @eval: 20

View file

@ -11,5 +11,6 @@ fun test() -> f64 {
sum(val)
}
// @ignore WIP
// @no-errors
// @type: 88 list<f64>

View file

@ -1,10 +1,15 @@
let x = 23;
let y = x * 2;
let z = print(y);
let z = y;
z;
fun test() -> f64 {
x + y
}
// @no-errors
// @type: 41 f64
// @type: 38 f64
// @eval: Float(69.0)
// @concrete:
// | File
// | LetStatement
@ -29,25 +34,38 @@ z;
// | Let:'"let"'
// | Identifier:'"z"'
// | Equal:'"="'
// | CallExpression
// | Identifier
// | Identifier:'"print"'
// | ArgumentList
// | LeftParen:'"("'
// | Argument
// | Identifier
// | Identifier:'"y"'
// | RightParen:'")"'
// | Identifier
// | Identifier:'"y"'
// | Semicolon:'";"'
// | ExpressionStatement
// | Identifier
// | Identifier:'"z"'
// | Semicolon:'";"'
// | FunctionDecl
// | Fun:'"fun"'
// | Identifier:'"test"'
// | ParamList
// | LeftParen:'"("'
// | RightParen:'")"'
// | ReturnType
// | Arrow:'"->"'
// | TypeExpression
// | Identifier:'"f64"'
// | Block
// | LeftBrace:'"{"'
// | ExpressionStatement
// | BinaryExpression
// | Identifier
// | Identifier:'"x"'
// | Plus:'"+"'
// | Identifier
// | Identifier:'"y"'
// | RightBrace:'"}"'
// |
// @compiles-to:
// | function << module >> (0 args, 0 locals):
// | strings (0):
// | code (14):
// | code (12):
// | 0: PushFloat(23.0)
// | 1: StoreModule(0)
// | 2: LoadModule(0)
@ -55,11 +73,16 @@ z;
// | 4: FloatMultiply
// | 5: StoreModule(1)
// | 6: LoadModule(1)
// | 7: LoadExternFunction(0)
// | 8: Call(1)
// | 9: StoreModule(2)
// | 10: LoadModule(2)
// | 11: Discard
// | 12: PushNothing
// | 13: Return
// | 7: StoreModule(2)
// | 8: LoadModule(2)
// | 9: Discard
// | 10: PushNothing
// | 11: Return
// | function test (0 args, 0 locals):
// | strings (0):
// | code (4):
// | 0: LoadModule(0)
// | 1: LoadModule(1)
// | 2: FloatAdd
// | 3: Return
// |

View file

@ -4,10 +4,16 @@ fun worst_fib(n: f64) -> f64 {
} else if n == 1 {
1
} else {
worst_fib(n-2) + worst_fib(n-1)
worst_fib(n-2) + delegate_worst_fib(n-1)
}
}
// NOTE: This nonsense exists to make sure mutual recursion works, in
// addition to direct recursion.
fun delegate_worst_fib(n: f64) -> f64 {
worst_fib(n)
}
fun test() -> f64 {
worst_fib(10)
}