@@ -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 (
0 commit comments