Skip to content

Commit

Permalink
test: add compiler diagnostic tests for majority of hir diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
junlarsen committed Feb 9, 2025
1 parent 21dce77 commit dcb3d08
Show file tree
Hide file tree
Showing 30 changed files with 292 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/ui/hir/constructing-non-struct-type.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

fn main() {
let foo = new i32 {};
}
11 changes: 11 additions & 0 deletions tests/ui/hir/constructing-non-struct-type.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::constructing_non_struct_type

× cannot construct a non-struct type
╭─[constructing-non-struct-type.eight:4:13]
3fn main() {
4let foo = new i32 {};
· ─────┬────
· ╰── the type i32 is not a struct type
5 │ }
╰────

9 changes: 9 additions & 0 deletions tests/ui/hir/constructing-pointer-type.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

struct Foo {
bar: i32,
}

fn main() {
let foo = new *Foo {};
}
12 changes: 12 additions & 0 deletions tests/ui/hir/constructing-pointer-type.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Error: sema::constructing_pointer_type

× cannot construct a pointer type
╭─[constructing-pointer-type.eight:8:13]
7fn main() {
8let foo = new *Foo {};
· ─────┬─────
· ╰── type *Foo is a pointer type and cannot be constructed
9 │ }
╰────
help: did you mean to construct the inner type?

5 changes: 5 additions & 0 deletions tests/ui/hir/dereference-of-non-pointer.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

fn main() {
let foo = *(1);
}
11 changes: 11 additions & 0 deletions tests/ui/hir/dereference-of-non-pointer.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::dereference_of_non_pointer

× type i32 is not a pointer type, and cannot be dereferenced
╭─[dereference-of-non-pointer.eight:4:13]
3fn main() {
4let foo = *(1);
· ──┬─
· ╰── i32 is not dereferenceable
5 │ }
╰────

7 changes: 7 additions & 0 deletions tests/ui/hir/function-type-mismatch.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

intrinsic_fn get_i32() -> i32;

fn main() {
let dummy = get_i32(1);
}
11 changes: 11 additions & 0 deletions tests/ui/hir/function-type-mismatch.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::function_type_mismatch

× function types do not take the same number of arguments
╭─[function-type-mismatch.eight:6:15]
5 │ fn main() {
6let dummy = get_i32(1);
· ─────┬────
· ╰── the function has type fn() -> i32
7 │ }
╰────

5 changes: 5 additions & 0 deletions tests/ui/hir/invalid-field-reference-of-non-struct.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

fn main(a: i32) {
let b = a.foo;
}
11 changes: 11 additions & 0 deletions tests/ui/hir/invalid-field-reference-of-non-struct.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::invalid_field_reference_of_non_struct

× type i32 is not a struct type and does not have fields
╭─[invalid-field-reference-of-non-struct.eight:4:13]
3fn main(a: i32) {
4 │ let b = a.foo;
· ─┬─
· ╰── unknown field foo
5 │ }
╰────

9 changes: 9 additions & 0 deletions tests/ui/hir/invalid-struct-field-reference.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

struct Foo {
bar: i32,
}

fn main(foo: Foo) {
let bar = foo.baz;
}
11 changes: 11 additions & 0 deletions tests/ui/hir/invalid-struct-field-reference.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::invalid_struct_field_reference

× invalid field reference to baz in type Foo
╭─[invalid-struct-field-reference.eight:8:17]
7fn main(foo: Foo) {
8 │ let bar = foo.baz;
· ─┬─
· ╰── unknown field baz
9 │ }
╰────

9 changes: 9 additions & 0 deletions tests/ui/hir/missing-field.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

struct Foo {
bar: i32,
}

fn main() {
let foo = new Foo {};
}
17 changes: 17 additions & 0 deletions tests/ui/hir/missing-field.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Error: sema::missing_field

× the field bar is missing in construction of Foo
╭─[missing-field.eight:4:3]
3struct Foo {
4bar: i32,
· ────┬────
· ╰── field bar defined here
5 │ }
6
7fn main() {
8let foo = new Foo {};
· ─────┬────
· ╰── construction does not name field bar
9 │ }
╰────

6 changes: 6 additions & 0 deletions tests/ui/hir/trait-does-not-exist.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

fn main() {
// Trait Add does not exist here
let a = 1 + 2;
}
11 changes: 11 additions & 0 deletions tests/ui/hir/trait-does-not-exist.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::trait_does_not_exist

× trait Add does not exist
╭─[trait-does-not-exist.eight:5:13]
4// Trait Add does not exist here
5let a = 1 + 2;
· ┬
· ╰── required trait Add to exist
6 │ }
╰────

11 changes: 11 additions & 0 deletions tests/ui/hir/trait-instance-missing-fn.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

trait Add<A, B, R> {
fn add(a: A, b: B) -> R;
}

instance Add<i32, i32, i32> {}

fn main() {
let a = 1 + 2;
}
11 changes: 11 additions & 0 deletions tests/ui/hir/trait-instance-missing-fn.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::trait_instance_missing_fn

× trait instance Add does not derive method add
╭─[trait-instance-missing-fn.eight:10:13]
9fn main() {
10let a = 1 + 2;
· ┬
· ╰── trait instance Add does not derive method add
11 │ }
╰────

12 changes: 12 additions & 0 deletions tests/ui/hir/trait-method-does-not-exist.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

trait Add<A, B, R> {
}

instance Add<i32, i32, i32> {
intrinsic_fn add(a: i32, b: i32) -> i32;
}

fn main() {
let a = 1 + 2;
}
11 changes: 11 additions & 0 deletions tests/ui/hir/trait-method-does-not-exist.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::trait_method_does_not_exist

× trait Add does not have method add
╭─[trait-method-does-not-exist.eight:11:13]
10fn main() {
11let a = 1 + 2;
· ┬
· ╰── required method add for trait Add
12 │ }
╰────

7 changes: 7 additions & 0 deletions tests/ui/hir/type-mismatch.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

intrinsic_fn get_i32() -> i32;

fn main() {
let dummy: bool = get_i32();
}
12 changes: 12 additions & 0 deletions tests/ui/hir/type-mismatch.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Error: sema::type_mismatch

× type mismatch
╭─[type-mismatch.eight:6:21]
5fn main() {
6 │ let dummy: bool = get_i32();
· ───┬────┬
· │ ╰── expected type bool
· ╰── the expression has type i32
7 │ }
╰────

9 changes: 9 additions & 0 deletions tests/ui/hir/unknown-field.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

struct Foo {
bar: i32,
}

fn main() {
let foo = new Foo { giggles: 123 };
}
11 changes: 11 additions & 0 deletions tests/ui/hir/unknown-field.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::unknown_field

× the type Foo does not have a field named giggles
╭─[unknown-field.eight:8:23]
7fn main() {
8 │ let foo = new Foo { giggles: 123 };
· ───┬───
· ╰── this field does not exist
9 │ }
╰────

3 changes: 3 additions & 0 deletions tests/ui/hir/unknown-intrinsic-type.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

intrinsic_type i69;
10 changes: 10 additions & 0 deletions tests/ui/hir/unknown-intrinsic-type.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Error: sema::unknown_intrinsic_type_type

× unknown intrinsic type i69
╭─[unknown-intrinsic-type.eight:3:16]
2
3intrinsic_type i69;
· ─┬─
· ╰── could not find type i69
╰────

7 changes: 7 additions & 0 deletions tests/ui/hir/wrong-function-type-argument-count.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

fn foo<T>(a: T, b: T) -> T {}

fn main() {
let foo = foo::<i32, bool>(1, 2);
}
12 changes: 12 additions & 0 deletions tests/ui/hir/wrong-function-type-argument-count.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Error: sema::wrong_function_type_argument_count

× function foo requires 1 type arguments, but 2 were supplied
╭─[wrong-function-type-argument-count.eight:6:13]
5 │ fn main() {
6let foo = foo::<i32, bool>(1, 2);
· ───────────┬──────────┬
· │ ╰── declares 1 type arguments
· ╰── supplied 2 type arguments
7 │ }
╰────

9 changes: 9 additions & 0 deletions tests/ui/hir/wrong-trait-type-argument-count.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

trait Add<A, B, R> {
fn add(a: A, b: B) -> R;
}

instance Add<i32, i32> {
intrinsic_fn add(a: i32, b: i32) -> i32;
}
17 changes: 17 additions & 0 deletions tests/ui/hir/wrong-trait-type-argument-count.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Error: sema::wrong_trait_type_argument_count

× trait Add requires 3 type arguments, but 2 were supplied
╭─[wrong-trait-type-argument-count.eight:3:7]
2
3trait Add<A, B, R> {
· ─┬─
· ╰── declares 3 type arguments
4 │ fn add(a: A, b: B) -> R;
5 │ }
6
7instance Add<i32, i32> {
· ─┬─
· ╰── supplied 2 type arguments
8 │ intrinsic_fn add(a: i32, b: i32) -> i32;
╰────

0 comments on commit dcb3d08

Please sign in to comment.