Skip to content

Commit

Permalink
chore: add some tests for type aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Oct 24, 2024
1 parent ec75e8e commit 600ffeb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg(test)]

mod aliases;
mod bound_checks;
mod imports;
mod metaprogramming;
Expand Down
52 changes: 52 additions & 0 deletions compiler/noirc_frontend/src/tests/aliases.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use super::assert_no_errors;

#[test]
fn allows_usage_of_type_alias_as_argument_type() {
let src = r#"
type Foo = Field;
fn accepts_a_foo(x: Foo) {
assert_eq(x, 42);
}
fn main() {
accepts_a_foo(42);
}
"#;
assert_no_errors(src);
}

#[test]
fn allows_usage_of_type_alias_as_return_type() {
let src = r#"
type Foo = Field;
fn returns_a_foo() -> Foo {
42
}
fn main() {
let _ = returns_a_foo();
}
"#;
assert_no_errors(src);
}

// This is a regression test for https://github.com/noir-lang/noir/issues/6347
#[test]
#[should_panic = r#"ResolverError(Expected { span: Span(Span { start: ByteIndex(95), end: ByteIndex(98) }), expected: "type", got: "type alias" }"#]
fn allows_destructuring_a_type_alias_of_a_struct() {
let src = r#"
struct Foo {
inner: Field
}
type Bar = Foo;
fn main() {
let Bar { inner } = Foo { inner: 42 };
assert_eq(inner, 42);
}
"#;
assert_no_errors(src);
}

0 comments on commit 600ffeb

Please sign in to comment.