Skip to content

Commit 3b91037

Browse files
authored
Fix: views in generic packages no longer cause type mismatch (#334)
1 parent 14a4d27 commit 3b91037

File tree

17 files changed

+357
-251
lines changed

17 files changed

+357
-251
lines changed

vhdl_lang/src/analysis.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ mod types;
3030

3131
#[cfg(test)]
3232
pub(crate) mod tests;
33+
3334
pub(crate) use root::{Library, LockedUnit};
3435

3536
pub use self::root::{DesignRoot, EntHierarchy};

vhdl_lang/src/analysis/declarative.rs

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -714,11 +714,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
714714
colon_token: _,
715715
} = attr_spec;
716716

717-
let attr_ent = match scope.lookup(
718-
self.ctx,
719-
ident.item.token,
720-
&Designator::Identifier(ident.item.name().clone()),
721-
) {
717+
let attr_ent = match scope.lookup(&Designator::Identifier(ident.item.name().clone())) {
722718
Ok(NamedEntities::Single(ent)) => {
723719
ident.set_unique_reference(ent);
724720
if let Some(attr_ent) = AttributeEnt::from_any(ent) {
@@ -748,7 +744,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
748744
return Ok(());
749745
}
750746
Err(err) => {
751-
diagnostics.push(err);
747+
diagnostics.push(err.into_diagnostic(self.ctx, ident.item.token));
752748
return Ok(());
753749
}
754750
};
@@ -758,55 +754,53 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
758754
signature,
759755
}) = entity_name
760756
{
761-
let ent: EntRef<'_> =
762-
match scope.lookup(self.ctx, designator.token, &designator.item.item) {
763-
Ok(NamedEntities::Single(ent)) => {
764-
designator.set_unique_reference(ent);
757+
let ent: EntRef<'_> = match scope.lookup(&designator.item.item) {
758+
Ok(NamedEntities::Single(ent)) => {
759+
designator.set_unique_reference(ent);
765760

766-
if let Some(signature) = signature {
767-
diagnostics.push(Diagnostic::should_not_have_signature(
768-
"Attribute specification",
769-
signature.pos(self.ctx),
770-
));
771-
}
772-
ent
761+
if let Some(signature) = signature {
762+
diagnostics.push(Diagnostic::should_not_have_signature(
763+
"Attribute specification",
764+
signature.pos(self.ctx),
765+
));
773766
}
774-
Ok(NamedEntities::Overloaded(overloaded)) => {
775-
if let Some(signature) = signature {
776-
match as_fatal(self.resolve_signature(scope, signature, diagnostics))? {
777-
Some(signature_key) => {
778-
if let Some(ent) =
779-
overloaded.get(&SubprogramKey::Normal(signature_key))
780-
{
781-
designator.set_unique_reference(&ent);
782-
ent.into()
783-
} else {
784-
diagnostics.push(Diagnostic::no_overloaded_with_signature(
785-
designator.pos(self.ctx),
786-
&designator.item.item,
787-
&overloaded,
788-
));
789-
return Ok(());
790-
}
791-
}
792-
None => {
767+
ent
768+
}
769+
Ok(NamedEntities::Overloaded(overloaded)) => {
770+
if let Some(signature) = signature {
771+
match as_fatal(self.resolve_signature(scope, signature, diagnostics))? {
772+
Some(signature_key) => {
773+
if let Some(ent) =
774+
overloaded.get(&SubprogramKey::Normal(signature_key))
775+
{
776+
designator.set_unique_reference(&ent);
777+
ent.into()
778+
} else {
779+
diagnostics.push(Diagnostic::no_overloaded_with_signature(
780+
designator.pos(self.ctx),
781+
&designator.item.item,
782+
&overloaded,
783+
));
793784
return Ok(());
794785
}
795786
}
796-
} else if let Some(ent) = overloaded.as_unique() {
797-
designator.set_unique_reference(ent);
798-
ent
799-
} else {
800-
diagnostics
801-
.push(Diagnostic::signature_required(designator.pos(self.ctx)));
802-
return Ok(());
787+
None => {
788+
return Ok(());
789+
}
803790
}
804-
}
805-
Err(err) => {
806-
diagnostics.push(err);
791+
} else if let Some(ent) = overloaded.as_unique() {
792+
designator.set_unique_reference(ent);
793+
ent
794+
} else {
795+
diagnostics.push(Diagnostic::signature_required(designator.pos(self.ctx)));
807796
return Ok(());
808797
}
809-
};
798+
}
799+
Err(err) => {
800+
diagnostics.push(err.into_diagnostic(self.ctx, designator.token));
801+
return Ok(());
802+
}
803+
};
810804

811805
// Attributes affect the underlying entity and cannot be set directly on aliases
812806
let ent = ent.as_actual();

vhdl_lang/src/analysis/design_unit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
519519
}
520520
Name::Designator(designator) => {
521521
let visible = scope
522-
.lookup(self.ctx, name.span, designator.designator())
522+
.lookup(designator.designator())
523+
.map_err(|err| err.into_diagnostic(self.ctx, name.span))
523524
.into_eval_result(diagnostics)?;
524525
designator.set_reference(&visible);
525526
Ok(UsedNames::Single(visible))

vhdl_lang/src/analysis/expression.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
238238
expr.pos(self.ctx),
239239
"Ambiguous expression. You can use a qualified expression type'(expr) to disambiguate.",
240240
ErrorCode::AmbiguousExpression,
241-
);
241+
);
242242
Err(EvalError::Unknown)
243243
}
244244
}
@@ -254,7 +254,8 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
254254
) -> EvalResult<Vec<OverloadedEnt<'a>>> {
255255
let designator = Designator::OperatorSymbol(op);
256256
match scope
257-
.lookup(self.ctx, op_pos, &designator)
257+
.lookup(&designator)
258+
.map_err(|err| err.into_diagnostic(self.ctx, op_pos))
258259
.into_eval_result(diagnostics)?
259260
{
260261
NamedEntities::Single(ent) => {
@@ -503,7 +504,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
503504
Literal::String(_) => Ok(ExpressionType::String),
504505
Literal::BitString(_) => Ok(ExpressionType::String),
505506
Literal::Character(chr) => {
506-
match scope.lookup(self.ctx, span, &Designator::Character(*chr)) {
507+
match scope.lookup(&Designator::Character(*chr)) {
507508
Ok(NamedEntities::Single(ent)) => {
508509
// Should never happen but better know if it does
509510
diagnostics.add(
@@ -543,7 +544,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
543544
}
544545
}
545546
Err(e) => {
546-
diagnostics.push(e);
547+
diagnostics.push(e.into_diagnostic(self.ctx, span));
547548
Err(EvalError::Unknown)
548549
}
549550
}
@@ -624,12 +625,10 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
624625
self.expr_pos_with_ttyp(scope, target_type, expr.span, &mut expr.item, diagnostics)
625626
}
626627

627-
fn implicit_bool_types(&self, scope: &Scope<'a>, span: TokenSpan) -> FnvHashSet<BaseType<'a>> {
628-
if let Ok(NamedEntities::Overloaded(overloaded)) = scope.lookup(
629-
self.ctx,
630-
span,
631-
&Designator::OperatorSymbol(Operator::QueQue),
632-
) {
628+
fn implicit_bool_types(&self, scope: &Scope<'a>) -> FnvHashSet<BaseType<'a>> {
629+
if let Ok(NamedEntities::Overloaded(overloaded)) =
630+
scope.lookup(&Designator::OperatorSymbol(Operator::QueQue))
631+
{
633632
overloaded
634633
.entities()
635634
.filter_map(|ent| ent.formals().nth(0).map(|typ| typ.type_mark().base()))
@@ -650,7 +649,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
650649
match types {
651650
ExpressionType::Unambiguous(typ) => {
652651
if typ.base() != self.boolean().base() {
653-
let implicit_bools = self.implicit_bool_types(scope, expr.span);
652+
let implicit_bools = self.implicit_bool_types(scope);
654653
if !implicit_bools.contains(&typ.base()) {
655654
diagnostics.add(
656655
expr.pos(self.ctx),
@@ -659,7 +658,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
659658
typ.describe(),
660659
self.boolean().describe()
661660
),
662-
ErrorCode::NoImplicitConversion
661+
ErrorCode::NoImplicitConversion,
663662
);
664663
}
665664
}
@@ -669,7 +668,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
669668
self.expr_with_ttyp(scope, self.boolean(), expr, diagnostics)?;
670669
} else {
671670
let implicit_bool_types: FnvHashSet<_> = self
672-
.implicit_bool_types(scope, expr.span)
671+
.implicit_bool_types(scope)
673672
.intersection(&types)
674673
.cloned()
675674
.collect();
@@ -1012,18 +1011,18 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
10121011
Diagnostic::new(
10131012
choice.pos(self.ctx),
10141013
format!(
1015-
"All elements of record '{}' are already associated",
1016-
record_type.designator()
1017-
),
1014+
"All elements of record '{}' are already associated",
1015+
record_type.designator()
1016+
),
10181017
ErrorCode::AlreadyAssociated,
10191018
)
1020-
.opt_related(
1021-
record_type.decl_pos(),
1022-
format!(
1023-
"Record '{}' defined here",
1024-
record_type.designator()
1019+
.opt_related(
1020+
record_type.decl_pos(),
1021+
format!(
1022+
"Record '{}' defined here",
1023+
record_type.designator()
1024+
),
10251025
),
1026-
),
10271026
)
10281027
}
10291028

vhdl_lang/src/analysis/literals.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,10 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
188188
scope: &Scope<'a>,
189189
unit: &mut WithRef<Ident>,
190190
) -> Result<TypeEnt<'a>, Diagnostic> {
191-
match scope.lookup(
192-
self.ctx,
193-
unit.item.token,
194-
&Designator::Identifier(unit.item.item.clone()),
195-
)? {
191+
match scope
192+
.lookup(&Designator::Identifier(unit.item.item.clone()))
193+
.map_err(|err| err.into_diagnostic(self.ctx, unit.item.token))?
194+
{
196195
NamedEntities::Single(unit_ent) => {
197196
unit.set_unique_reference(unit_ent);
198197
if let AnyEntKind::PhysicalLiteral(physical_ent) = unit_ent.actual_kind() {

vhdl_lang/src/analysis/names.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<'a> ResolvedName<'a> {
251251
}
252252
AnyEntKind::Overloaded(_) => {
253253
return Err((
254-
"Internal error. Unreachable as overloded is handled outside this function"
254+
"Internal error. Unreachable as overloaded is handled outside this function"
255255
.to_string(),
256256
ErrorCode::Internal,
257257
));
@@ -1213,7 +1213,8 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
12131213
let mut resolved = match SplitName::from_name(name) {
12141214
SplitName::Designator(designator) => {
12151215
let name = scope
1216-
.lookup(self.ctx, span, designator.designator())
1216+
.lookup(designator.designator())
1217+
.map_err(|err| err.into_diagnostic(self.ctx, span))
12171218
.into_eval_result(diagnostics)?;
12181219
return Ok(match name {
12191220
NamedEntities::Single(ent) => {

vhdl_lang/src/analysis/overloaded.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,8 @@ mod tests {
453453
panic!("Expected designator")
454454
};
455455

456-
let overloaded = if let NamedEntities::Overloaded(overloaded) = self
457-
.scope
458-
.lookup(&self.tokens, fcall.span, &des.item)
459-
.unwrap()
456+
let overloaded = if let NamedEntities::Overloaded(overloaded) =
457+
self.scope.lookup(&des.item).unwrap()
460458
{
461459
overloaded
462460
} else {

0 commit comments

Comments
 (0)