Skip to content

Commit

Permalink
[flow][errors] Eliminate last usage of ExplanationAlreadyPrinted
Browse files Browse the repository at this point in the history
Summary:
I want to ensure that `intermediate_error` contains no `Friendly.message_feature`, which contains a lot of strings that are mostly constant, but very wasteful to send between processes. The end goal is that we will send `intermediate_error` to the main process instead, which will contain already decided primary error location.

This diff starts with the easy one: we get rid of `ExplanationAlreadyPrinted`. We just need to add two more variants.

Changelog: [internal]

Reviewed By: panagosg7

Differential Revision: D56164157

fbshipit-source-id: 4e73c5a1a9ea7ffc97288b13b162d4911956f34d
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Apr 16, 2024
1 parent 358d3be commit 51c5573
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
17 changes: 4 additions & 13 deletions src/typing/errors/error_message.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
open Type
open Reason
open Utils_js
open Flow_intermediate_error_types

exception EDebugThrow of ALoc.t

Expand Down Expand Up @@ -2228,7 +2229,7 @@ type 'loc friendly_message_recipe =
loc: 'loc;
features: Loc.t Flow_errors_utils.Friendly.message_feature list;
use_op: 'loc Type.virtual_use_op;
explanation: Loc.t Flow_errors_utils.Friendly.message_feature list option;
explanation: 'loc explanation option;
}
| PropPolarityMismatch of {
prop: string option;
Expand Down Expand Up @@ -4923,25 +4924,15 @@ let friendly_message_of_msg loc_of_aloc msg =
loc;
features = lower @ [text " but "] @ upper;
use_op;
explanation =
Some
[
text
"React hooks and other functions are not compatible with each other, because hooks cannot be called conditionally";
];
explanation = Some ExplanationReactHookIncompatibleWithNormalFunctions;
}
| EHookUniqueIncompatible { use_op; lower; upper } ->
UseOp
{
loc = loc_of_reason lower;
features = [ref lower; text " and "; ref upper; text " are different React hooks"];
use_op;
explanation =
Some
[
text
"Different React hooks are not compatible with each other, because hooks cannot be called conditionally";
];
explanation = Some ExplanationReactHookIncompatibleWithEachOther;
}
| EHookNaming _ ->
Normal { features = [text "Hooks must have names that begin with "; code "use"; text "."] }
Expand Down
12 changes: 10 additions & 2 deletions src/typing/errors/flow_intermediate_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,6 @@ let rec make_intermediate_error :
(Flow_error.code_of_error error)
(MessageAlreadyFriendlyPrinted features)
| (None, UseOp { loc; features; use_op; explanation }) ->
let explanation = Base.Option.map explanation ~f:(fun e -> ExplanationAlreadyPrinted e) in
mk_use_op_error loc use_op ?explanation (MessageAlreadyFriendlyPrinted features)
| (None, PropMissing { loc; prop; reason_obj; use_op; suggestion }) ->
mk_prop_missing_error loc prop reason_obj use_op suggestion
Expand Down Expand Up @@ -1061,7 +1060,6 @@ let to_printable_error :
let ref = Friendly.ref_map loc_of_aloc in
let desc = Friendly.desc_of_reason_desc in
let explanation_to_friendly_msgs = function
| ExplanationAlreadyPrinted features -> features
| ExplanationAbstractEnumCasting ->
[
text "You can explicitly cast your enum value to its representation type using ";
Expand Down Expand Up @@ -1160,6 +1158,16 @@ let to_printable_error :
ref (mk_reason (RCustom "hook arguments") props_loc);
text " and their nested elements cannot be written to";
]
| ExplanationReactHookIncompatibleWithEachOther ->
[
text
"Different React hooks are not compatible with each other, because hooks cannot be called conditionally";
]
| ExplanationReactHookIncompatibleWithNormalFunctions ->
[
text
"React hooks and other functions are not compatible with each other, because hooks cannot be called conditionally";
]
| ExplanationReactHookReturnDeepReadOnly hook_loc ->
[
text "The return value of a ";
Expand Down
3 changes: 2 additions & 1 deletion src/typing/errors/flow_intermediate_error_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ open Reason

type 'loc explanation =
| ExplanationAbstractEnumCasting
| ExplanationAlreadyPrinted of Loc.t Flow_errors_utils.Friendly.message_feature list
| ExplanationArrayInvariantTyping
| ExplanationConstrainedAssign of {
name: string;
Expand All @@ -26,6 +25,8 @@ type 'loc explanation =
| ExplanationReactComponentPropsDeepReadOnly of 'loc
| ExplanationReactComponentRefRequirement
| ExplanationReactHookArgsDeepReadOnly of 'loc
| ExplanationReactHookIncompatibleWithEachOther
| ExplanationReactHookIncompatibleWithNormalFunctions
| ExplanationReactHookReturnDeepReadOnly of 'loc
| ExplanationRenderTypeRequirement
| ExplanationTypeGuardCompatibility
Expand Down

0 comments on commit 51c5573

Please sign in to comment.