-
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: type checking for list & map literals (#751)
Closes #712 ### Summary of Changes Don't allow calls that produce no or multiple results inside list & map literals. In other cases, the existing type checking already took care of this.
- Loading branch information
1 parent
52374aa
commit dc14223
Showing
4 changed files
with
84 additions
and
1 deletion.
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
16 changes: 16 additions & 0 deletions
16
packages/safe-ds-lang/tests/resources/validation/types/checking/lists/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,16 @@ | ||
package tests.validation.types.checking.lists | ||
|
||
fun noResults() | ||
fun oneResult() -> r: Int | ||
fun twoResults() -> (r1: Int, r2: Int) | ||
|
||
segment mySegment() { | ||
[ | ||
// $TEST$ error "Cannot add a value of type '()' to a list." | ||
»noResults()«, | ||
// $TEST$ no error r"Cannot add a value of type '.*' to a list\." | ||
»oneResult()«, | ||
// $TEST$ error "Cannot add a value of type '(r1: Int, r2: Int)' to a list." | ||
»twoResults()« | ||
]; | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/safe-ds-lang/tests/resources/validation/types/checking/maps/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,19 @@ | ||
package tests.validation.types.checking.maps | ||
|
||
fun noResults() | ||
fun oneResult() -> r: Int | ||
fun twoResults() -> (r1: Int, r2: Int) | ||
|
||
segment mySegment() { | ||
{ | ||
// $TEST$ error "Cannot use a value of type '()' as a map key." | ||
// $TEST$ error "Cannot use a value of type '()' as a map value." | ||
»noResults()«: »noResults()«, | ||
// $TEST$ no error r"Cannot use a value of type '.*' as a map key\." | ||
// $TEST$ no error r"Cannot use a value of type '.*' as a map value\." | ||
»oneResult()«: »oneResult()«, | ||
// $TEST$ error "Cannot use a value of type '(r1: Int, r2: Int)' as a map key." | ||
// $TEST$ error "Cannot use a value of type '(r1: Int, r2: Int)' as a map value." | ||
»twoResults()«: »twoResults()« | ||
}; | ||
} |