@@ -55,8 +55,8 @@ let errorExpectedTypeText ppf typeClashContext =
55
55
| _ -> fprintf ppf " But it's expected to have type:"
56
56
57
57
let printExtraTypeClashHelp ppf trace typeClashContext =
58
- match typeClashContext with
59
- | Some (MathOperator {forFloat; operator; isConstant} ) -> (
58
+ match ( typeClashContext, trace) with
59
+ | Some (MathOperator {forFloat; operator; isConstant} ), _ -> (
60
60
let operatorForOtherType =
61
61
match operator with
62
62
| "+" -> " +."
@@ -77,16 +77,31 @@ let printExtraTypeClashHelp ppf trace typeClashContext =
77
77
| _ -> " compute"
78
78
in
79
79
(* TODO check int vs float explicitly before showing this *)
80
- fprintf ppf
81
- " \n\n \
82
- \ Floats and ints have their own mathematical operators. This means you \
83
- cannot %s a float and an int without converting between the two.\n\n \
84
- \ Possible solutions:\n \
85
- \ - Ensure all values in this calculation has the type @{<info>%s@}. \
86
- You can convert between floats and ints via @{<info>Belt.Float.toInt@} \
87
- and @{<info>Belt.Int.fromFloat@}."
88
- operatorText
89
- (if forFloat then " float" else " int" );
80
+ (match (operator, trace) with
81
+ | ( " +" ,
82
+ [
83
+ ({Types. desc = Tconstr (p1, _, _)}, _);
84
+ ({desc = Tconstr (p2, _, _)}, _);
85
+ ] )
86
+ when Path. same Predef. path_string p1 || Path. same Predef. path_string p2 ->
87
+ fprintf ppf
88
+ " \n\n \
89
+ \ Are you looking to concatenate strings? Use the operator \
90
+ @{<info>++@}, which concatenates strings.\n\n \
91
+ \ Possible solutions:\n \
92
+ \ - Change the @{<info>+@} operator to @{<info>++@} to concatenate \
93
+ strings instead."
94
+ | _ ->
95
+ fprintf ppf
96
+ " \n\n \
97
+ \ Floats and ints have their own mathematical operators. This means \
98
+ you cannot %s a float and an int without converting between the two.\n\n \
99
+ \ Possible solutions:\n \
100
+ \ - Ensure all values in this calculation has the type @{<info>%s@}. \
101
+ You can convert between floats and ints via \
102
+ @{<info>Belt.Float.toInt@} and @{<info>Belt.Int.fromFloat@}."
103
+ operatorText
104
+ (if forFloat then " float" else " int" ));
90
105
match (isConstant, trace) with
91
106
| Some constant , _ ->
92
107
if forFloat then
@@ -115,30 +130,30 @@ let printExtraTypeClashHelp ppf trace typeClashContext =
115
130
(if forFloat then " int" else " float" )
116
131
| _ -> () )
117
132
| _ -> () )
118
- | Some Switch ->
133
+ | Some Switch , _ ->
119
134
fprintf ppf
120
135
" \n\n \
121
136
\ All branches in a @{<info>switch@} must return the same type. To fix \
122
137
this, change your branch to return the expected type."
123
- | Some IfCondition ->
138
+ | Some IfCondition , _ ->
124
139
fprintf ppf
125
140
" \n\n \
126
141
\ To fix this, change the highlighted code so it evaluates to a \
127
142
@{<info>bool@}."
128
- | Some IfReturn ->
143
+ | Some IfReturn , _ ->
129
144
fprintf ppf
130
145
" \n\n \
131
146
\ @{<info>if@} expressions must return the same type in all branches \
132
147
(@{<info>if@}, @{<info>else if@}, @{<info>else@})."
133
- | Some MaybeUnwrapOption ->
148
+ | Some MaybeUnwrapOption , _ ->
134
149
fprintf ppf
135
150
" \n\n \
136
151
\ Possible solutions:\n \
137
152
\ - Unwrap the option to its underlying value using \
138
153
`yourValue->Belt.Option.getWithDefault(someDefaultValue)`"
139
- | Some ComparisonOperator ->
154
+ | Some ComparisonOperator , _ ->
140
155
fprintf ppf " \n\n You can only compare things of the same type."
141
- | Some ArrayValue ->
156
+ | Some ArrayValue , _ ->
142
157
fprintf ppf
143
158
" \n\n \
144
159
\ Arrays can only contain items of the same type.\n\n \
0 commit comments