diff --git a/src/typing/statement.ml b/src/typing/statement.ml index ffe1b630cba..02a649a7cb3 100644 --- a/src/typing/statement.ml +++ b/src/typing/statement.ml @@ -6490,8 +6490,8 @@ module Make let open Ast.Expression in let rec super_expr (loc, expr) = match expr with - | Identifier (id_loc, id) -> - let t = identifier cx id id_loc in + | Identifier (id_loc, ({ Ast.Identifier.name; comments = _ } as id)) -> + let t = Type_env.sig_var_ref cx (OrdinaryName name) id_loc in (t, (fun () -> ((loc, t), Identifier ((id_loc, t), id)))) | Member { diff --git a/src/typing/type_env.ml b/src/typing/type_env.ml index ac0c72067b2..9871d730c57 100644 --- a/src/typing/type_env.ml +++ b/src/typing/type_env.ml @@ -675,6 +675,15 @@ let var_ref ?(lookup_mode = ForValue) cx ?desc name loc = let t = query_var ~lookup_mode cx name ?desc loc in Flow_js.reposition cx loc t +let sig_var_ref ?(lookup_mode = ForValue) cx ?desc name loc = + let desc = + match desc with + | Some desc -> desc + | None -> RIdentifier name + in + let reason = mk_reason desc loc in + AnnotT (reason, query_var cx ~lookup_mode name loc, true) + let read_class_self_type cx loc = match checked_find_loc_env_write_opt cx Env_api.ClassSelfLoc loc with | Some t -> t diff --git a/src/typing/type_env.mli b/src/typing/type_env.mli index 55d3eccad5e..1d4dc4502db 100644 --- a/src/typing/type_env.mli +++ b/src/typing/type_env.mli @@ -118,6 +118,14 @@ val var_ref : ALoc.t -> Type.t +val sig_var_ref : + ?lookup_mode:LookupMode.t -> + Context.t -> + ?desc:Reason.reason_desc -> + Reason.name -> + ALoc.t -> + Type.t + val intrinsic_ref : Context.t -> ?desc:Reason.reason_desc -> Reason.name -> ALoc.t -> (Type.t * ALoc.t) option diff --git a/tests/autocomplete/autocomplete.exp b/tests/autocomplete/autocomplete.exp index 658e4239ebf..08d4ba13fe8 100644 --- a/tests/autocomplete/autocomplete.exp +++ b/tests/autocomplete/autocomplete.exp @@ -2679,6 +2679,10 @@ class_declaration_name.js:5:8 Flags: --pretty {"result":[]} +class_extends.js:5:20 +Flags: --pretty +{"result":[{"name":"Foo","type":"class Foo"},{"name":"function","type":""}]} + pattern_object_key_middle.js:6:12 Flags: --pretty {"result":[{"name":"foobar","type":"string"}]} diff --git a/tests/autocomplete/class_extends.js b/tests/autocomplete/class_extends.js new file mode 100644 index 00000000000..2ea594acb0e --- /dev/null +++ b/tests/autocomplete/class_extends.js @@ -0,0 +1,6 @@ +// @flow + +class Foo {} + +class Bar extends F +// ^ diff --git a/tests/autocomplete/test.sh b/tests/autocomplete/test.sh index ded51893d8f..7b487bedbc0 100755 --- a/tests/autocomplete/test.sh +++ b/tests/autocomplete/test.sh @@ -76,6 +76,7 @@ queries_in_file autocomplete "enums.js" --lsp queries_in_file autocomplete "enum-key.js" --lsp queries_in_file autocomplete "enum-id.js" --pretty queries_in_file autocomplete "class_declaration_name.js" --pretty +queries_in_file autocomplete "class_extends.js" --pretty queries_in_file autocomplete "pattern_object_key_middle.js" --pretty queries_in_file autocomplete "iterator.js" --lsp queries_in_file autocomplete "indexed-access-1.js" --lsp diff --git a/tests/extends/extends.exp b/tests/extends/extends.exp index 21d67e25862..757230f2f69 100644 --- a/tests/extends/extends.exp +++ b/tests/extends/extends.exp @@ -14,19 +14,16 @@ References: Error ---------------------------------------------------------------------------------------------------- test.js:30:17 -Cannot extend `D` [1] with `obj` because object type [2] is not inheritable. [incompatible-use] +Cannot extend `D` [1] with `obj` because `obj` [2] is not inheritable. [incompatible-use] test.js:30:17 30| class D extends obj {} - ^^^ + ^^^ [2] References: test.js:30:7 30| class D extends obj {} ^ [1] - test.js:29:18 - 29| declare var obj: {}; - ^^ [2] diff --git a/tests/rec/rec.exp b/tests/rec/rec.exp index 856133948e6..5051fddfcc8 100644 --- a/tests/rec/rec.exp +++ b/tests/rec/rec.exp @@ -339,20 +339,17 @@ References: Error ----------------------------------------------------------------------------------------------- this_subst.js:1:53 -Cannot extend `InstrumentedContainer` [1] with `container` because uninitialized variable [2] is not inheritable. +Cannot extend `InstrumentedContainer` [1] with `container` because `container` [2] is not inheritable. [incompatible-use] this_subst.js:1:53 1| var container = class InstrumentedContainer extends container { - ^^^^^^^^^ + ^^^^^^^^^ [2] References: this_subst.js:1:23 1| var container = class InstrumentedContainer extends container { ^^^^^^^^^^^^^^^^^^^^^ [1] - this_subst.js:1:5 - 1| var container = class InstrumentedContainer extends container { - ^^^^^^^^^ [2]