@@ -99,7 +99,7 @@ type type_clash_context =
9999 operator : string ;
100100 is_constant : string option ;
101101 }
102- | FunctionArgument of {optional : bool }
102+ | FunctionArgument of {optional : bool ; name : string option }
103103 | Statement of type_clash_statement
104104 | ForLoopCondition
105105
@@ -138,11 +138,17 @@ let error_type_text ppf type_clash_context =
138138
139139let error_expected_type_text ppf type_clash_context =
140140 match type_clash_context with
141- | Some (FunctionArgument {optional} ) ->
142- fprintf ppf " But this%s function argument is expecting: "
141+ | Some (FunctionArgument {optional; name } ) ->
142+ fprintf ppf " But this%s function argument"
143143 (match optional with
144144 | false -> " "
145- | true -> " optional" )
145+ | true -> " optional" );
146+
147+ (match name with
148+ | Some name -> fprintf ppf " @{<info>~%s@}" name
149+ | None -> () );
150+
151+ fprintf ppf " is expecting:"
146152 | Some ComparisonOperator ->
147153 fprintf ppf " But it's being compared to something of type:"
148154 | Some SwitchReturn -> fprintf ppf " But this switch is expected to return:"
@@ -158,21 +164,21 @@ let error_expected_type_text ppf type_clash_context =
158164 fprintf ppf " But this @{<info>if@} statement is expected to return:"
159165 | Some ArrayValue ->
160166 fprintf ppf " But this array is expected to have items of type:"
161- | Some (SetRecordField _ ) -> fprintf ppf " But this record field is of type:"
167+ | Some (SetRecordField _ ) -> fprintf ppf " But the record field is of type:"
162168 | Some
163169 (RecordField {field_name = " children" ; jsx = Some {jsx_type = `Fragment }})
164170 ->
165- fprintf ppf " But children of JSX fragments is expected to have type:"
171+ fprintf ppf " But children of JSX fragments are expected to have type:"
166172 | Some
167173 (RecordField
168174 {field_name = " children" ; jsx = Some {jsx_type = `CustomComponent }}) ->
169175 fprintf ppf
170- " But children passed to this component is expected to have type:"
176+ " But children passed to this component are expected to have type:"
171177 | Some (RecordField {field_name; jsx = Some _ } ) ->
172- fprintf ppf " But this component prop @{<info>%s@} is expected to have type:"
178+ fprintf ppf " But the component prop @{<info>%s@} is expected to have type:"
173179 field_name
174180 | Some (RecordField {field_name} ) ->
175- fprintf ppf " But this record field @{<info>%s@} is expected to have type:"
181+ fprintf ppf " But the record field @{<info>%s@} is expected to have type:"
176182 field_name
177183 | Some (Statement FunctionCall) -> fprintf ppf " But it's expected to return:"
178184 | Some (MathOperator {operator} ) ->
@@ -429,9 +435,8 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env loc ppf
429435 @,\
430436 @{<info>%s@} is an optional record field, and you're passing an \
431437 optional value to it.@,\
432- Optional fields expect you to pass the concrete value, not an option, \
433- when passed directly.\n \
434- \ @,\
438+ Optional fields expect you to pass the concrete value, not an option.\n \
439+ \ @,\
435440 Possible solutions: @,\
436441 - Unwrap the option and pass a concrete value directly@,\
437442 - If you really do want to pass the optional value, prepend the value \
@@ -447,8 +452,8 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env loc ppf
447452 @,\
448453 You're passing an optional value into an optional function argument.@,\
449454 Optional function arguments expect you to pass the concrete value, not \
450- an option, when passed directly .\n \
451- \ @,\
455+ an option.\n \
456+ \ @,\
452457 Possible solutions: @,\
453458 - Unwrap the option and pass a concrete value directly@,\
454459 - If you really do want to pass the optional value, prepend the value \
@@ -510,9 +515,9 @@ let type_clash_context_from_function sexp sfunct =
510515 Some (MathOperator {for_float = true ; operator; is_constant})
511516 | Pexp_ident {txt = Lident (("/" | "*" | "+" | "-" ) as operator )} ->
512517 Some (MathOperator {for_float = false ; operator; is_constant})
513- | _ -> Some ( FunctionArgument {optional = false })
518+ | _ -> None
514519
515- let type_clash_context_for_function_argument type_clash_context sarg0 =
520+ let type_clash_context_for_function_argument ~ label type_clash_context sarg0 =
516521 match type_clash_context with
517522 | Some (MathOperator {for_float; operator} ) ->
518523 Some
@@ -527,7 +532,16 @@ let type_clash_context_for_function_argument type_clash_context sarg0 =
527532 Some txt
528533 | _ -> None );
529534 })
530- | None -> Some (FunctionArgument {optional = false })
535+ | None ->
536+ Some
537+ (FunctionArgument
538+ {
539+ optional = false ;
540+ name =
541+ (match label with
542+ | Asttypes. Nolabel -> None
543+ | Optional {txt = l } | Labelled {txt = l } -> Some l);
544+ })
531545 | type_clash_context -> type_clash_context
532546
533547let type_clash_context_maybe_option ty_expected ty_res =
0 commit comments