-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CCA: static check that the state classes are not overlapping
Since all the types in StateUnion can be set on state (represented currently as class on body tag), if the enum values overlap they will have the same runtime values, and might cause strange issue if the two enum are used as different things. Add a type level check for this. Bug: None Test: cca.py tsc <board> Test: cca.py tsc <board> failed with CL:4318103 reverted Change-Id: I8e25628abdca3b3e0322d728999db362c4f5ce57 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4321738 Reviewed-by: Shik Chen <shik@chromium.org> Commit-Queue: Pi-Hsun Shih <pihsun@chromium.org> Auto-Submit: Pi-Hsun Shih <pihsun@chromium.org> Reviewed-by: Chu-Hsuan Yang <chuhsuan@chromium.org> Cr-Commit-Position: refs/heads/main@{#1115553}
- Loading branch information
1 parent
802bd98
commit 4551167
Showing
3 changed files
with
49 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
/** | ||
* Asserts that the given type is never. | ||
*/ | ||
export type AssertNever<T extends never> = T; | ||
|
||
type CheckEnumValuesOverlapImpl<Union, Overlap, Enums> = | ||
Enums extends [infer Enum extends string, ...infer Rest] ? | ||
CheckEnumValuesOverlapImpl< | ||
Union|`${Enum}`, Overlap|(Union&`${Enum}`), Rest>: | ||
Overlap; | ||
|
||
/** | ||
* Checks that a tuple of enum have pairwise non-overlapping values. | ||
* | ||
* The result type will be |never| if there's no overlap, and union of the | ||
* overlapped values if there's overlap. | ||
*/ | ||
export type CheckEnumValuesOverlap<Enums extends string[]> = | ||
CheckEnumValuesOverlapImpl<never, never, Enums>; |