Skip to content

Commit

Permalink
Fuzz: "thread '<unnamed>' panicked at compiler/qsc_frontend/src/typec…
Browse files Browse the repository at this point in the history
…k/rules.rs:368:57:" (ubuntu-latest) (#848)

When an attriute expression includes the nested definition of an item,
we were incorrectly checking the type signatures of that item even
though it was not included in early parts of type checking, leading to a
panic. This update correctly ignores items in attributes for both phases
of type checking instead of just the first one.

Fixes #846
  • Loading branch information
swernli authored Nov 10, 2023
1 parent d0f6102 commit 1ca3143
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions compiler/qsc_frontend/src/lower/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2189,3 +2189,29 @@ fn duplicate_commas_in_arg_tuple() {
ctl-adj: <none>"#]],
);
}

#[test]
fn ignore_item_in_attribute() {
check_hir(
"namespace Test {
@Attr{function Bar() : Unit { Bar }}
function Foo() : Unit {}
}",
&expect![[r#"
Package:
Item 0 [0-112] (Public):
Namespace (Ident 5 [10-14] "Test"): Item 1
Item 1 [29-102] (Public):
Parent: 0
Callable 0 [78-102] (function):
name: Ident 1 [87-90] "Foo"
input: Pat 2 [90-92] [Type Unit]: Unit
output: Unit
functors: empty set
body: SpecDecl 3 [78-102]: Impl:
Block 4 [100-102]: <empty>
adj: <none>
ctl: <none>
ctl-adj: <none>"#]],
);
}
3 changes: 3 additions & 0 deletions compiler/qsc_frontend/src/typeck/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,7 @@ impl Visitor<'_> for ItemChecker<'_> {
self.checker.check_callable_decl(self.names, decl);
visit::walk_callable_decl(self, decl);
}

// We do not typecheck attributes, as they are verified during lowering.
fn visit_attr(&mut self, _: &ast::Attr) {}
}
2 changes: 2 additions & 0 deletions compiler/qsc_parse/src/item/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,7 @@ fn callable_missing_parens() {
]"#]],
)
}

#[test]
fn callable_missing_close_parens() {
check_vec(
Expand Down Expand Up @@ -1346,6 +1347,7 @@ fn callable_missing_close_parens() {
]"#]],
)
}

#[test]
fn callable_missing_open_parens() {
check_vec(
Expand Down

0 comments on commit 1ca3143

Please sign in to comment.