-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simplify computed types (#866)
### Summary of Changes Apply various simplification rules to computed type to improve their readability: * Replace `literal<>` with `Nothing` * Replace `literal<null>` with `Nothing?` * Remove duplicate entries from literal types * Replace `union<>` with `Nothing` * Remove entries from union types that are a subtype of another entry * Flatten nested union types
- Loading branch information
1 parent
a1f24e0
commit bde3274
Showing
18 changed files
with
264 additions
and
15 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
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
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
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
12 changes: 12 additions & 0 deletions
12
...esources/typing/simplification/remove duplicate constants from literal types/main.sdstest
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,12 @@ | ||
package tests.typing.simplification.removeDuplicateConstantsFromLiteralTypes | ||
|
||
class C( | ||
// $TEST$ serialization literal<1> | ||
p1: »literal<1, 1>«, | ||
|
||
// $TEST$ serialization literal<1, 2> | ||
p2: »literal<1, 2>«, | ||
|
||
// $TEST$ serialization literal<1, 1.0> | ||
p3: »literal<1, 1.0>«, | ||
) |
53 changes: 53 additions & 0 deletions
53
...sts/resources/typing/simplification/remove unneeded entries from union types/main.sdstest
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,53 @@ | ||
package tests.typing.simplification.removeUnneededEntriesFromUnionTypes | ||
|
||
class C( | ||
// $TEST$ serialization Int | ||
p1: »union<Int, Int>«, | ||
|
||
// $TEST$ serialization union<Int, String> | ||
p2: »union<Int, String, Int>«, | ||
|
||
|
||
// $TEST$ serialization Number | ||
p3: »union<Int, Number>«, | ||
|
||
// $TEST$ serialization Number | ||
p4: »union<Number, Int>«, | ||
|
||
// $TEST$ serialization Number? | ||
p5: »union<Number, Int?>«, | ||
|
||
// $TEST$ serialization Any | ||
p6: »union<Int, Number, Any>«, | ||
|
||
// $TEST$ serialization Any | ||
p7: »union<Any, Number, Int>«, | ||
|
||
// $TEST$ serialization Any? | ||
p8: »union<Int, Number?, Any>«, | ||
|
||
|
||
// $TEST$ serialization union<Int, String> | ||
p9: »union<Int, String>«, | ||
|
||
// $TEST$ serialization union<Int, String?> | ||
p10: »union<Int, String?>«, | ||
|
||
// $TEST$ serialization union<Number, String> | ||
p11: »union<Int, Number, String>«, | ||
|
||
// $TEST$ serialization union<Number, String> | ||
p12: »union<Number, Int, String>«, | ||
|
||
// $TEST$ serialization Any | ||
p13: »union<Int, String, Any>«, | ||
|
||
// $TEST$ serialization Any? | ||
p14: »union<Int, String?, Any>«, | ||
|
||
// $TEST$ serialization Any | ||
p15: »union<Any, String, Int>«, | ||
|
||
// $TEST$ serialization Any? | ||
p16: »union<Any, String?, Int>«, | ||
) |
6 changes: 6 additions & 0 deletions
6
...sts/resources/typing/simplification/replace empty literal types with Nothing/main.sdstest
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,6 @@ | ||
package tests.typing.simplification.replaceEmptyLiteralTypesWithNothing | ||
|
||
class C( | ||
// $TEST$ serialization Nothing | ||
p1: »literal<>« | ||
) |
6 changes: 6 additions & 0 deletions
6
...tests/resources/typing/simplification/replace empty union types with Nothing/main.sdstest
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,6 @@ | ||
package tests.typing.simplification.replaceEmptyUnionTypesWithNothing | ||
|
||
class C( | ||
// $TEST$ serialization Nothing | ||
p1: »union<>« | ||
) |
9 changes: 9 additions & 0 deletions
9
...plification/replace literals types that allow only null with NothingNullable/main.sdstest
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,9 @@ | ||
package tests.typing.simplification.replaceLiteralTypesThatAllowOnlyNullWithNothingNullable | ||
|
||
class C( | ||
// $TEST$ serialization Nothing? | ||
p1: »literal<null>«, | ||
|
||
// $TEST$ serialization Nothing? | ||
p2: »literal<null, null>« | ||
) |
Oops, something went wrong.