From e430f33e0ec05157ea2ca4bcc9bab57d6ef3b98b Mon Sep 17 00:00:00 2001 From: dalance Date: Wed, 26 Jun 2024 18:43:46 +0900 Subject: [PATCH] Fix stack overflow at symbol resolver --- crates/analyzer/src/symbol_table.rs | 7 +++++++ crates/analyzer/src/tests.rs | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/crates/analyzer/src/symbol_table.rs b/crates/analyzer/src/symbol_table.rs index 0aa6e4ad..9a6de7cc 100644 --- a/crates/analyzer/src/symbol_table.rs +++ b/crates/analyzer/src/symbol_table.rs @@ -107,6 +107,13 @@ impl SymbolTable { kind: &TypeKind, ) -> Result, 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, diff --git a/crates/analyzer/src/tests.rs b/crates/analyzer/src/tests.rs index 467d34b8..7c3d5b76 100644 --- a/crates/analyzer/src/tests.rs +++ b/crates/analyzer/src/tests.rs @@ -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 { .. })); +}