Skip to content

Commit

Permalink
[flow][match] Tests for error on duplicate binding name
Browse files Browse the repository at this point in the history
Summary: Add tests for duplicate binding name (we already error here).

Reviewed By: SamChou19815

Differential Revision: D67502322

fbshipit-source-id: 16c4935f36eaa573ff67487aa3fe665b933b0fef
  • Loading branch information
gkz authored and facebook-github-bot committed Dec 20, 2024
1 parent f4f5e1e commit 186aa6d
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
72 changes: 71 additions & 1 deletion tests/match/match.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -659,4 +729,4 @@ References:



Found 51 errors
Found 56 errors
14 changes: 14 additions & 0 deletions tests/match/pattern-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

0 comments on commit 186aa6d

Please sign in to comment.