Skip to content

Commit 7ed5e78

Browse files
authored
Fix: discrete ranges can be used as choice statements (#354)
1 parent 5cf0e4c commit 7ed5e78

40 files changed

+375
-223
lines changed

vhdl_lang/src/analysis/assignment.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::ast::*;
1212
use crate::data::*;
1313
use crate::named_entity::*;
1414

15-
impl<'a, 't> AnalyzeContext<'a, 't> {
15+
impl<'a> AnalyzeContext<'a, '_> {
1616
// @TODO maybe make generic function for expression/waveform.
1717
// wait until type checking to see if it makes sense
1818
pub fn analyze_expr_assignment(
@@ -55,7 +55,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
5555
} in alternatives.iter_mut()
5656
{
5757
self.analyze_expression_for_target(scope, ttyp, item, diagnostics)?;
58-
self.choice_with_ttyp(scope, ctyp, choices, diagnostics)?;
58+
self.choices_with_ttyp(scope, ctyp, choices, diagnostics)?;
5959
}
6060
}
6161
}
@@ -105,7 +105,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
105105
} in alternatives.iter_mut()
106106
{
107107
self.analyze_waveform(scope, ttyp, item, diagnostics)?;
108-
self.choice_with_ttyp(scope, ctyp, choices, diagnostics)?;
108+
self.choices_with_ttyp(scope, ctyp, choices, diagnostics)?;
109109
}
110110
}
111111
}

vhdl_lang/src/analysis/association.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'a> ResolvedFormal<'a> {
8484
}
8585
}
8686

87-
impl<'a, 't> AnalyzeContext<'a, 't> {
87+
impl<'a> AnalyzeContext<'a, '_> {
8888
fn resolve_formal(
8989
&self,
9090
formal_region: &FormalRegion<'a>,

vhdl_lang/src/analysis/concurrent.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::named_entity::*;
1414
use crate::{HasTokenSpan, TokenSpan};
1515
use analyze::*;
1616

17-
impl<'a, 't> AnalyzeContext<'a, 't> {
17+
impl<'a> AnalyzeContext<'a, '_> {
1818
pub fn analyze_concurrent_part(
1919
&self,
2020
scope: &Scope<'a>,
@@ -188,7 +188,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
188188
ref mut item,
189189
span: _,
190190
} = alternative;
191-
self.choice_with_ttyp(scope, ctyp, choices, diagnostics)?;
191+
self.choices_with_ttyp(scope, ctyp, choices, diagnostics)?;
192192
let nested = scope.nested();
193193
self.analyze_generate_body(&nested, parent, item, src_span, diagnostics)?;
194194
}

vhdl_lang/src/analysis/declarative.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl Declaration {
134134
}
135135
}
136136

137-
impl<'a, 't> AnalyzeContext<'a, 't> {
137+
impl<'a> AnalyzeContext<'a, '_> {
138138
pub fn analyze_declarative_part(
139139
&self,
140140
scope: &Scope<'a>,

vhdl_lang/src/analysis/design_unit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::named_entity::*;
1414
use crate::HasTokenSpan;
1515
use analyze::*;
1616

17-
impl<'a, 't> AnalyzeContext<'a, 't> {
17+
impl<'a> AnalyzeContext<'a, '_> {
1818
pub fn analyze_primary_unit(
1919
&self,
2020
unit: &mut AnyPrimaryUnit,

vhdl_lang/src/analysis/expression.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub(super) struct TypeMatcher<'c, 'a, 't> {
6969
context: &'c AnalyzeContext<'a, 't>,
7070
}
7171

72-
impl<'c, 'a, 't> TypeMatcher<'c, 'a, 't> {
72+
impl<'a> TypeMatcher<'_, 'a, '_> {
7373
// Returns true if the expression types is possible given the target type
7474
pub fn is_possible(&self, types: &ExpressionType<'a>, ttyp: BaseType<'a>) -> bool {
7575
if types.match_type(ttyp) {
@@ -213,6 +213,22 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
213213
self.any_matcher().can_be_target_type(typ, ttyp)
214214
}
215215

216+
pub fn check_type_mismatch(
217+
&self,
218+
typ: TypeEnt<'a>,
219+
ttyp: TypeEnt<'a>,
220+
pos: TokenSpan,
221+
diagnostics: &mut dyn DiagnosticHandler,
222+
) {
223+
if !self.can_be_target_type(typ, ttyp.base()) {
224+
diagnostics.push(Diagnostic::type_mismatch(
225+
&pos.pos(self.ctx),
226+
&typ.describe(),
227+
ttyp,
228+
));
229+
}
230+
}
231+
216232
pub fn expr_unknown_ttyp(
217233
&self,
218234
scope: &Scope<'a>,
@@ -684,7 +700,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
684700
"Ambiguous use of implicit boolean conversion ??",
685701
ErrorCode::AmbiguousCall,
686702
);
687-
diag.add_type_candididates("Could be", implicit_bool_types);
703+
diag.add_type_candidates("Could be", implicit_bool_types);
688704
diagnostics.push(diag);
689705
}
690706

@@ -697,7 +713,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
697713
),
698714
ErrorCode::AmbiguousExpression,
699715
);
700-
diag.add_type_candididates(
716+
diag.add_type_candidates(
701717
"Implicit boolean conversion operator ?? is not defined for",
702718
types,
703719
);
@@ -741,13 +757,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
741757
if let Some(type_mark) =
742758
as_fatal(self.analyze_qualified_expression(scope, qexpr, diagnostics))?
743759
{
744-
if !self.can_be_target_type(type_mark, target_base.base()) {
745-
diagnostics.push(Diagnostic::type_mismatch(
746-
&span.pos(self.ctx),
747-
&type_mark.describe(),
748-
target_type,
749-
));
750-
}
760+
self.check_type_mismatch(type_mark, target_type, span, diagnostics);
751761
}
752762
}
753763
Expression::Binary(ref mut op, ref mut left, ref mut right) => {
@@ -772,14 +782,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
772782
))? {
773783
Some(Disambiguated::Unambiguous(overloaded)) => {
774784
let op_type = overloaded.return_type().unwrap();
775-
776-
if !self.can_be_target_type(op_type, target_type.base()) {
777-
diagnostics.push(Diagnostic::type_mismatch(
778-
&span.pos(self.ctx),
779-
&op_type.describe(),
780-
target_type,
781-
));
782-
}
785+
self.check_type_mismatch(op_type, target_type, span, diagnostics);
783786
}
784787
Some(Disambiguated::Ambiguous(candidates)) => {
785788
diagnostics.push(Diagnostic::ambiguous_op(
@@ -815,14 +818,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
815818
))? {
816819
Some(Disambiguated::Unambiguous(overloaded)) => {
817820
let op_type = overloaded.return_type().unwrap();
818-
819-
if !self.can_be_target_type(op_type, target_type.base()) {
820-
diagnostics.push(Diagnostic::type_mismatch(
821-
&span.pos(self.ctx),
822-
&op_type.describe(),
823-
target_type,
824-
));
825-
}
821+
self.check_type_mismatch(op_type, target_type, span, diagnostics);
826822
}
827823
Some(Disambiguated::Ambiguous(candidates)) => {
828824
diagnostics.push(Diagnostic::ambiguous_op(

vhdl_lang/src/analysis/literals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::data::*;
1414
use crate::named_entity::*;
1515
use crate::TokenSpan;
1616

17-
impl<'a, 't> AnalyzeContext<'a, 't> {
17+
impl<'a> AnalyzeContext<'a, '_> {
1818
/// Analyze a string literal or expanded bit-string literal for type-matching
1919
fn analyze_string_literal(
2020
&self,

vhdl_lang/src/analysis/lock.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub struct ReadGuard<'a, T, R> {
112112
guard: RwLockReadGuard<'a, AnalysisState<T, R>>,
113113
}
114114

115-
impl<'a, T, R> ReadGuard<'a, T, R> {
115+
impl<T, R> ReadGuard<'_, T, R> {
116116
pub fn result(&self) -> &R {
117117
self.guard.result.as_ref().unwrap()
118118
}
@@ -122,7 +122,7 @@ impl<'a, T, R> ReadGuard<'a, T, R> {
122122
}
123123
}
124124

125-
impl<'a, T, R> std::ops::Deref for ReadGuard<'a, T, R> {
125+
impl<T, R> std::ops::Deref for ReadGuard<'_, T, R> {
126126
type Target = T;
127127

128128
fn deref(&self) -> &Self::Target {
@@ -148,15 +148,15 @@ impl<'a, T, R> WriteGuard<'a, T, R> {
148148
}
149149
}
150150

151-
impl<'a, T, R> std::ops::Deref for WriteGuard<'a, T, R> {
151+
impl<T, R> std::ops::Deref for WriteGuard<'_, T, R> {
152152
type Target = T;
153153

154154
fn deref(&self) -> &Self::Target {
155155
&self.guard.data
156156
}
157157
}
158158

159-
impl<'a, T, R> std::ops::DerefMut for WriteGuard<'a, T, R> {
159+
impl<T, R> std::ops::DerefMut for WriteGuard<'_, T, R> {
160160
fn deref_mut(&mut self) -> &mut Self::Target {
161161
&mut self.guard.data
162162
}

0 commit comments

Comments
 (0)