Skip to content

Commit d522ece

Browse files
committed
Check array constraint in type generic mapping
1 parent 7ce293a commit d522ece

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

vhdl_lang/src/analysis/package_instance.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,33 @@ impl<'a> AnalyzeContext<'a> {
8484
match name.as_mut() {
8585
// Could be an array constraint such as integer_vector(0 to 3)
8686
// @TODO we ignore the suffix for now
87-
Name::Slice(prefix, _) => self.type_name(
88-
scope,
89-
&prefix.pos,
90-
&mut prefix.item,
91-
diagnostics,
92-
)?,
87+
Name::Slice(prefix, drange) => {
88+
let typ = self.type_name(
89+
scope,
90+
&prefix.pos,
91+
&mut prefix.item,
92+
diagnostics,
93+
)?;
94+
if let Type::Array { indexes, .. } = typ.base().kind() {
95+
if let Some(Some(idx_typ)) = indexes.get(0) {
96+
self.drange_with_ttyp(
97+
scope,
98+
(*idx_typ).into(),
99+
drange,
100+
diagnostics,
101+
)?;
102+
}
103+
} else {
104+
diagnostics.error(
105+
&assoc.actual.pos,
106+
format!(
107+
"Array constraint cannot be used for {}",
108+
typ.describe()
109+
),
110+
);
111+
}
112+
typ
113+
}
93114
// Could be a record constraint such as rec_t(field(0 to 3))
94115
// @TODO we ignore the suffix for now
95116
Name::CallOrIndexed(call) if call.could_be_indexed_name() => self

0 commit comments

Comments
 (0)