From 186aa6da2780ba68c21836a63321e3eeeaa56aff Mon Sep 17 00:00:00 2001 From: George Zahariev Date: Fri, 20 Dec 2024 13:29:36 -0800 Subject: [PATCH] [flow][match] Tests for error on duplicate binding name Summary: Add tests for duplicate binding name (we already error here). Reviewed By: SamChou19815 Differential Revision: D67502322 fbshipit-source-id: 16c4935f36eaa573ff67487aa3fe665b933b0fef --- tests/match/match.exp | 72 ++++++++++++++++++++++++++++++++++- tests/match/pattern-errors.js | 14 +++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/tests/match/match.exp b/tests/match/match.exp index 162d583b87b..1e7bbfb9791 100644 --- a/tests/match/match.exp +++ b/tests/match/match.exp @@ -534,6 +534,76 @@ Duplicate property `foo` in object pattern. [match-invalid-pattern] ^^^^^ +Error ------------------------------------------------------------------------------------------ pattern-errors.js:76:23 + +Cannot declare `a` [1] because the name is already bound. [name-already-bound] + + pattern-errors.js:76:23 + 76| [const a, true as a]: 0, // ERROR + ^ + +References: + pattern-errors.js:76:12 + 76| [const a, true as a]: 0, // ERROR + ^ [1] + + +Error ------------------------------------------------------------------------------------------ pattern-errors.js:77:29 + +Cannot declare `a` [1] because the name is already bound. [name-already-bound] + + pattern-errors.js:77:29 + 77| [const a, true as const a]: 0, // ERROR + ^ + +References: + pattern-errors.js:77:12 + 77| [const a, true as const a]: 0, // ERROR + ^ [1] + + +Error ------------------------------------------------------------------------------------------ pattern-errors.js:78:21 + +Cannot declare `a` [1] because the name is already bound. [name-already-bound] + + pattern-errors.js:78:21 + 78| [const a, const a]: 0, // ERROR + ^ + +References: + pattern-errors.js:78:12 + 78| [const a, const a]: 0, // ERROR + ^ [1] + + +Error ------------------------------------------------------------------------------------------ pattern-errors.js:79:24 + +Cannot declare `a` [1] because the name is already bound. [name-already-bound] + + pattern-errors.js:79:24 + 79| [const a, ...const a]: 0, // ERROR + ^ + +References: + pattern-errors.js:79:12 + 79| [const a, ...const a]: 0, // ERROR + ^ [1] + + +Error ------------------------------------------------------------------------------------------ pattern-errors.js:80:24 + +Cannot declare `a` [1] because the name is already bound. [name-already-bound] + + pattern-errors.js:80:24 + 80| {const a, ...const a}: 0, // ERROR + ^ + +References: + pattern-errors.js:80:12 + 80| {const a, ...const a}: 0, // ERROR + ^ [1] + + Error -------------------------------------------------------------------------------------------------- patterns.js:9:3 Cannot cast `out` to empty because number [1] is incompatible with empty [2]. [incompatible-cast] @@ -659,4 +729,4 @@ References: -Found 51 errors +Found 56 errors diff --git a/tests/match/pattern-errors.js b/tests/match/pattern-errors.js index c602a7e7422..9f604b4dafa 100644 --- a/tests/match/pattern-errors.js +++ b/tests/match/pattern-errors.js @@ -67,3 +67,17 @@ _: 0, }; } + +// Duplicate binding names +{ + declare const x: [boolean, boolean] | {a: boolean, b: boolean}; + + const e1 = match (x) { + [const a, true as a]: 0, // ERROR + [const a, true as const a]: 0, // ERROR + [const a, const a]: 0, // ERROR + [const a, ...const a]: 0, // ERROR + {const a, ...const a}: 0, // ERROR + _: 0, + }; +}