Skip to content

Commit cfeee95

Browse files
gkzmeta-codesync[bot]
authored andcommitted
[flow][records] Update language of cannot reassign binding error for records
Summary: Update language of cannot reassign binding error for records Changelog: [internal] Reviewed By: marcoww6 Differential Revision: D87011454 fbshipit-source-id: c4d04e7daa47436dce44bbed856538a2fb510431
1 parent d601918 commit cfeee95

File tree

7 files changed

+21
-6
lines changed

7 files changed

+21
-6
lines changed

src/analysis/bindings.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type kind =
3232
| GeneratorNext
3333
| Component
3434
| ComponentParameter
35+
| Record
3536
[@@deriving show]
3637

3738
type 'loc entry = ('loc, 'loc) Ast.Identifier.t * kind

src/analysis/bindings.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type kind =
3232
| GeneratorNext
3333
| Component
3434
| ComponentParameter
35+
| Record
3536
[@@deriving show]
3637

3738
type 'loc t

src/analysis/env_builder/name_resolver.ml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,16 @@ module Make (Context : C) (FlowAPIUtils : F with type cx = Context.t) :
784784
binding_kind = Flow_intermediate_error_types.ClassNameBinding;
785785
}
786786
)
787+
| (Bindings.Record, AssignmentWrite) ->
788+
let def_reason = mk_reason (RIdentifier (OrdinaryName name)) def_loc in
789+
Some
790+
(Error_message.EAssignConstLikeBinding
791+
{
792+
loc = assignment_loc;
793+
definition = def_reason;
794+
binding_kind = Flow_intermediate_error_types.RecordNameBinding;
795+
}
796+
)
787797
| (Bindings.Function, AssignmentWrite) ->
788798
let def_reason = mk_reason (RIdentifier (OrdinaryName name)) def_loc in
789799
Some
@@ -832,7 +842,7 @@ module Make (Context : C) (FlowAPIUtils : F with type cx = Context.t) :
832842
Error_message.(
833843
EBindingError (EVarRedeclaration, assignment_loc, OrdinaryName name, def_loc)
834844
)
835-
| ( Bindings.(Const | Let | Class | Function | Component | Import | Type _),
845+
| ( Bindings.(Const | Let | Class | Record | Function | Component | Import | Type _),
836846
( VarBinding | LetBinding | ClassBinding | ConstBinding | FunctionBinding
837847
| ComponentBinding )
838848
)
@@ -1636,7 +1646,7 @@ module Make (Context : C) (FlowAPIUtils : F with type cx = Context.t) :
16361646
heap_refinements = ref HeapRefinementMap.empty;
16371647
kind;
16381648
}
1639-
| Bindings.(Class | Enum) ->
1649+
| Bindings.(Class | Enum | Record) ->
16401650
let (havoc, providers) = this#providers_of_def_loc loc in
16411651
let write_entries =
16421652
Base.List.fold
@@ -1999,6 +2009,7 @@ module Make (Context : C) (FlowAPIUtils : F with type cx = Context.t) :
19992009
| Bindings.Const
20002010
| Bindings.Let
20012011
| Bindings.Class
2012+
| Bindings.Record
20022013
| Bindings.Function
20032014
| Bindings.Component
20042015
| Bindings.Parameter

src/analysis/hoister.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class ['loc] lexical_hoister ~flowmin_compatibility ~enable_enums =
264264
method! record_declaration _loc (record : ('loc, 'loc) Ast.Statement.RecordDeclaration.t) =
265265
let open Ast.Statement.RecordDeclaration in
266266
let { id; _ } = record in
267-
this#add_const_binding ~kind:Bindings.Class id;
267+
this#add_const_binding ~kind:Bindings.Record id;
268268
record
269269
end
270270

src/typing/errors/flow_intermediate_error_types.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ type assigned_const_like_binding_type =
1212
| FunctionNameBinding
1313
| DeclaredFunctionNameBinding
1414
| ComponentNameBinding
15+
| RecordNameBinding
1516

1617
let string_of_assigned_const_like_binding_type = function
1718
| ClassNameBinding -> "class"
1819
| FunctionNameBinding -> "function"
1920
| DeclaredFunctionNameBinding -> "declared function"
2021
| ComponentNameBinding -> "component"
22+
| RecordNameBinding -> "record"
2123

2224
type docblock_error =
2325
| MultipleFlowAttributes

tests/records/declaration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ interface Equatable<T> {
306306

307307
x.a as number; // OK
308308

309-
R = null; // ERROR: cannot reassign - TODO: records - update error message language
309+
R = null; // ERROR: cannot reassign
310310
}
311311

312312
// Multiple generic parameters

tests/records/records.exp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ References:
162162

163163
Error --------------------------------------------------------------------------------------------- declaration.js:309:3
164164

165-
Cannot reassign class binding `R` [1]. [cannot-reassign]
165+
Cannot reassign record binding `R` [1]. [cannot-reassign]
166166

167167
declaration.js:309:3
168-
309| R = null; // ERROR: cannot reassign - TODO: records - update error message language
168+
309| R = null; // ERROR: cannot reassign
169169
^
170170

171171
References:

0 commit comments

Comments
 (0)