Skip to content

Commit

Permalink
Fix stack overflow at symbol resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Jun 26, 2024
1 parent 555265b commit e430f33
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/analyzer/src/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ impl SymbolTable {
kind: &TypeKind,
) -> Result<ResolveContext<'a>, ResolveError> {
if let TypeKind::UserDefined(ref x) = kind {
// Detect infinite loop in trace_user_defined
if let Some(last_found) = context.last_found {
if *x.first().unwrap() == last_found.token.text {
return Ok(context);
}
}

let symbol = self.resolve(&SymbolPath::new(x), &context.namespace)?;
match symbol.found.kind {
SymbolKind::SystemVerilog => context.sv_member = true,
Expand Down
13 changes: 13 additions & 0 deletions crates/analyzer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2034,3 +2034,16 @@ fn r#unsafe() {
let errors = analyze(code);
assert!(matches!(errors[0], AnalyzerError::UnknownUnsafe { .. }));
}

#[test]
fn detect_recursive() {
let code = r#"
module ModuleA (
x: input x,
) {
}
"#;

let errors = analyze(code);
assert!(matches!(errors[0], AnalyzerError::MismatchType { .. }));
}

0 comments on commit e430f33

Please sign in to comment.