-
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: error if callable type is used in wrong context (#763)
Closes #713 ### Summary of Changes Callables are only supposed to be used as arguments to provide a clean graphical view. Likewise, we now show an error if a callable type is used for anything but a parameter.
- Loading branch information
1 parent
8cb2120
commit 9b1522f
Showing
7 changed files
with
151 additions
and
20 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
71 changes: 71 additions & 0 deletions
71
...s/safe-ds-lang/tests/resources/validation/other/types/callable 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,71 @@ | ||
package tests.validation.other.types.callableTypes.context | ||
|
||
annotation MyAnnotation( | ||
// $TEST$ no error "Callable types must only be used for parameters." | ||
p: »() -> ()«, | ||
) | ||
|
||
class MyClass<T>( | ||
// $TEST$ no error "Callable types must only be used for parameters." | ||
p: »() -> ()«, | ||
) { | ||
// $TEST$ error "Callable types must only be used for parameters." | ||
attr a: »() -> ()« | ||
} | ||
|
||
enum MyEnum { | ||
MyEnumVariant<T>( | ||
// $TEST$ no error "Callable types must only be used for parameters." | ||
p: »() -> ()«, | ||
) | ||
} | ||
|
||
fun myFunction( | ||
// $TEST$ no error "Callable types must only be used for parameters." | ||
p: »() -> ()«, | ||
) -> ( | ||
// $TEST$ error "Callable types must only be used for parameters." | ||
r: »() -> ()«, | ||
) | ||
|
||
segment mySegment1( | ||
// $TEST$ no error "Callable types must only be used for parameters." | ||
p: »() -> ()«, | ||
) -> ( | ||
// $TEST$ error "Callable types must only be used for parameters." | ||
r: »() -> ()«, | ||
) {} | ||
|
||
segment mySegment2( | ||
// $TEST$ no error "Callable types must only be used for parameters." | ||
// $TEST$ error "Callable types must only be used for parameters." | ||
c: (p: »() -> ()«) -> (r: »() -> ()«), | ||
) { | ||
// $TEST$ no error "Callable types must only be used for parameters." | ||
( | ||
p: »() -> ()«, | ||
) {}; | ||
|
||
// $TEST$ no error "Callable types must only be used for parameters." | ||
( | ||
p: »() -> ()«, | ||
) -> 1; | ||
} | ||
|
||
segment mySegment3( | ||
// $TEST$ error "Callable types must only be used for parameters." | ||
p1: MyClass<»() -> ()«>, | ||
|
||
// $TEST$ error "Callable types must only be used for parameters." | ||
p2: MyEnum.MyEnumVariant<»() -> ()«>, | ||
) {} | ||
|
||
segment mySegment4( | ||
// $TEST$ error "Callable types must only be used for parameters." | ||
p1: »() -> ()«.MyClass | ||
) {} | ||
|
||
segment mySegment5( | ||
// $TEST$ error "Callable types must only be used for parameters." | ||
p1: union<»() -> ()«> | ||
) {} |
16 changes: 16 additions & 0 deletions
16
...safe-ds-lang/tests/resources/validation/other/types/callable 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.callableTypes.context | ||
|
||
/* | ||
* We already show an error for the outer callable type, if it's used in the wrong context. | ||
*/ | ||
|
||
class MyClass1 { | ||
// $TEST$ no error "Callable types must only be used for parameters." | ||
attr a: () -> (r: »() -> ()«) | ||
} | ||
|
||
class MyClass2 { | ||
// $TEST$ no error "Callable types must only be used for parameters." | ||
// $TEST$ no error "Callable types must only be used for parameters." | ||
attr a: () -> (r: (p: »() -> ()«) -> (r: »() -> ()«)) | ||
} |
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