diff --git a/vhdl_lang/src/analysis/range.rs b/vhdl_lang/src/analysis/range.rs index 53c7cef9..e25363a2 100644 --- a/vhdl_lang/src/analysis/range.rs +++ b/vhdl_lang/src/analysis/range.rs @@ -117,7 +117,12 @@ impl<'a> AnalyzeContext<'a> { }; if let Some((_, indexes)) = typ.array_type() { - Ok(indexes.first().unwrap().unwrap()) + if let Some(first) = indexes.first().unwrap() { + Ok(*first) + } else { + // There was probably an error in the type definition of this signal/variable + Err(EvalError::Unknown) + } } else { diagnostics.error( &attr.name.pos, diff --git a/vhdl_lang/src/analysis/tests/assignment_typecheck.rs b/vhdl_lang/src/analysis/tests/assignment_typecheck.rs index d8b2ea6f..d8411940 100644 --- a/vhdl_lang/src/analysis/tests/assignment_typecheck.rs +++ b/vhdl_lang/src/analysis/tests/assignment_typecheck.rs @@ -548,3 +548,35 @@ end architecture; ], ); } + +#[test] +fn issue_177() { + let mut builder = LibraryBuilder::new(); + let code = builder.code( + "libname", + " +package Test is + type MyArray_t is array (0 to kConst) of integer; +end Test; + +package body Test is + variable v : MyArray_t := (others => 0); + procedure Foo is + begin + -- v'range previously paniced due to MyArray_t having None as index + for i in v'range loop + v(i) := 1; + end loop; + end procedure Foo; +end package body Test;", + ); + + let diagnostics = builder.analyze(); + check_diagnostics( + diagnostics, + vec![Diagnostic::error( + code.s1("kConst"), + "No declaration of 'kConst'", + )], + ) +}