Skip to content

Commit

Permalink
Fix #177
Browse files Browse the repository at this point in the history
  • Loading branch information
kraigher committed Jun 17, 2023
1 parent ec67fa0 commit 1258959
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion vhdl_lang/src/analysis/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 32 additions & 0 deletions vhdl_lang/src/analysis/tests/assignment_typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
)],
)
}

0 comments on commit 1258959

Please sign in to comment.