-
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: check context of union types (#677)
Closes #675 ### Summary of Changes Union types are now only allowed as parameters of annotations, classes, and functions. This way, no values with a union type appear inside pipelines or segments.
- Loading branch information
1 parent
4656c25
commit e846b59
Showing
12 changed files
with
181 additions
and
22 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
61 changes: 61 additions & 0 deletions
61
tests/resources/validation/other/types/union types/context/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,61 @@ | ||
package tests.validation.other.types.unionTypes.context | ||
|
||
annotation MyAnnotation( | ||
// $TEST$ no error "Union types must only be used for parameters of annotations, classes, and functions." | ||
p: »union<Int>«, | ||
) | ||
|
||
class MyClass<T>( | ||
// $TEST$ no error "Union types must only be used for parameters of annotations, classes, and functions." | ||
p: »union<Int>«, | ||
) { | ||
// $TEST$ error "Union types must only be used for parameters of annotations, classes, and functions." | ||
attr a: »union<Int>« | ||
} | ||
|
||
enum MyEnum { | ||
MyEnumVariant<T>( | ||
// $TEST$ error "Union types must only be used for parameters of annotations, classes, and functions." | ||
p: »union<Int>«, | ||
) | ||
} | ||
|
||
fun myFunction( | ||
// $TEST$ no error "Union types must only be used for parameters of annotations, classes, and functions." | ||
p: »union<Int>«, | ||
) -> ( | ||
// $TEST$ error "Union types must only be used for parameters of annotations, classes, and functions." | ||
r: »union<Int>«, | ||
) | ||
|
||
segment mySegment1( | ||
// $TEST$ error "Union types must only be used for parameters of annotations, classes, and functions." | ||
p: »union<Int>«, | ||
) -> ( | ||
// $TEST$ error "Union types must only be used for parameters of annotations, classes, and functions." | ||
r: »union<Int>«, | ||
) {} | ||
|
||
segment mySegment2( | ||
// $TEST$ error "Union types must only be used for parameters of annotations, classes, and functions." | ||
// $TEST$ error "Union types must only be used for parameters of annotations, classes, and functions." | ||
c: (p: »union<Int>«) -> (r: »union<Int>«), | ||
) { | ||
// $TEST$ error "Union types must only be used for parameters of annotations, classes, and functions." | ||
( | ||
p: »union<Int>«, | ||
) {}; | ||
|
||
// $TEST$ error "Union types must only be used for parameters of annotations, classes, and functions." | ||
( | ||
p: »union<Int>«, | ||
) -> 1; | ||
} | ||
|
||
segment mySegment3( | ||
// $TEST$ error "Union types must only be used for parameters of annotations, classes, and functions." | ||
p1: MyClass<»union<Int>«>, | ||
|
||
// $TEST$ error "Union types must only be used for parameters of annotations, classes, and functions." | ||
p2: MyEnum.MyEnumVariant<»union<Int>«>, | ||
) {} |
16 changes: 16 additions & 0 deletions
16
tests/resources/validation/other/types/union types/context/nested.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,16 @@ | ||
package tests.validation.other.types.unionTypes.context | ||
|
||
/* | ||
* We already show an error for the outer union type, if it's used in the wrong context. | ||
*/ | ||
|
||
class MyClass1 { | ||
// $TEST$ no error "Union types must only be used for parameters of annotations, classes, and functions." | ||
attr a: union<Int, »union<Int>«> | ||
} | ||
|
||
class MyClass2 { | ||
// $TEST$ no error "Union types must only be used for parameters of annotations, classes, and functions." | ||
// $TEST$ no error "Union types must only be used for parameters of annotations, classes, and functions." | ||
attr a: union<Int, (p: »union<Int>«) -> (r: »union<Int>«)> | ||
} |
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: 6 additions & 6 deletions
12
tests/resources/validation/other/types/union types/must have 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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
package tests.validation.other.types.unionTypes.mustHaveTypes | ||
|
||
// $TEST$ error "A union type must have at least one type." | ||
segment mySegment1( | ||
fun myFunction1( | ||
p: union»<>« | ||
) {} | ||
) | ||
|
||
// $TEST$ no error "A union type must have at least one type." | ||
segment mySegment2( | ||
fun myFunction2( | ||
p: union»<Int>« | ||
) {} | ||
) | ||
|
||
// $TEST$ no error "A union type must have at least one type." | ||
segment mySegment3( | ||
fun myFunction3( | ||
p: union»<Int, Float>« | ||
) {} | ||
) |