From 9c2d24c0010953a03d1830a37ff7cfb9569ee779 Mon Sep 17 00:00:00 2001 From: Pieter Vanderwerff Date: Wed, 26 Apr 2023 19:35:46 -0700 Subject: [PATCH] Ensure reparseTypeAnnotationAsIdFlow checks for type parameters Summary: The `reparseTypeAnnotationAsIdFlow` Reviewed By: avp Differential Revision: D45331985 fbshipit-source-id: 5f44610243aacf0cfbffb937ea327a318ef08002 --- lib/Parser/JSParserImpl-flow.cpp | 6 ++++-- .../flow/predicate-asserts-type-params-error.js | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/Parser/flow/predicate-asserts-type-params-error.js diff --git a/lib/Parser/JSParserImpl-flow.cpp b/lib/Parser/JSParserImpl-flow.cpp index 4881ce164bd..cadebbd7843 100644 --- a/lib/Parser/JSParserImpl-flow.cpp +++ b/lib/Parser/JSParserImpl-flow.cpp @@ -3093,8 +3093,10 @@ Optional JSParserImpl::reparseTypeAnnotationAsIdFlow( } else if ( auto *generic = dyn_cast(typeAnnotation)) { - if (auto *genericId = dyn_cast(generic->_id)) { - id = genericId->_name; + if (!generic->_typeParameters) { + if (auto *genericId = dyn_cast(generic->_id)) { + id = genericId->_name; + } } } diff --git a/test/Parser/flow/predicate-asserts-type-params-error.js b/test/Parser/flow/predicate-asserts-type-params-error.js new file mode 100644 index 00000000000..40ae5baba21 --- /dev/null +++ b/test/Parser/flow/predicate-asserts-type-params-error.js @@ -0,0 +1,13 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// RUN: (! %hermesc -parse-flow -dump-ast -pretty-json %s 2>&1) | %FileCheck %s --match-full-lines + +function foo(x: mixed): asserts x is number {} +// CHECK: {{.*}}:10:25: error: identifier expected +// CHECK: function foo(x: mixed): asserts x is number {} +// CHECK: ^~~~~~~~~~~~