-
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 lambda is used in wrong context
- Loading branch information
1 parent
097764d
commit 12d9826
Showing
6 changed files
with
457 additions
and
3 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
191 changes: 191 additions & 0 deletions
191
...esources/validation/other/expressions/lambdas/context/assigned to typed parameter.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,191 @@ | ||
package tests.validation.other.expressions.lambdas.assignedToTypedParameter | ||
|
||
/* | ||
* Lambdas passed as default values | ||
*/ | ||
|
||
@Repeatable | ||
annotation MyAnnotation( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f: () -> () = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g: () -> r: Int = »() -> 1« | ||
) | ||
|
||
class MyClass( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f: () -> () = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g: () -> r: Int = ((»() -> 1«)) | ||
) | ||
|
||
enum MyEnum { | ||
MyEnumVariant( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f: () -> () = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g: () -> r: Int = ((»() -> 1«)) | ||
) | ||
} | ||
|
||
fun myFunction( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f: () -> () = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g: () -> r: Int = ((»() -> 1«)) | ||
) | ||
|
||
segment mySegment1( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f: () -> () = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g: () -> r: Int = ((»() -> 1«)) | ||
) {} | ||
|
||
segment mySegment2( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f: (p: () -> () = »() {}«) -> (), | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g: (p: () -> (r: Int) = ((»() -> 1«))) -> (), | ||
) { | ||
( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f: () -> () = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g: () -> r: Int = ((»() -> 1«)) | ||
) {}; | ||
|
||
( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f: () -> () = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g: () -> r: Int = ((»() -> 1«)) | ||
) -> 1; | ||
} | ||
|
||
/* | ||
* Lambdas passed as arguments | ||
*/ | ||
|
||
@MyAnnotation( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
»() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
((»() -> 1«)) | ||
) | ||
@MyAnnotation( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g = ((»() -> 1«)) | ||
) | ||
segment lambdasPassedAsArguments( | ||
callableType: (p: () -> (), q: () -> (r: Int)) -> (), | ||
) { | ||
val blockLambda = (p: () -> (), q: () -> (r: Int)) {}; | ||
val expressionLambda = (p: () -> (), q: () -> (r: Int)) -> 1; | ||
|
||
MyAnnotation( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
»() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
((»() -> 1«)) | ||
); | ||
MyAnnotation( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g = ((»() -> 1«)) | ||
); | ||
|
||
MyClass( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
»() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
((»() -> 1«)) | ||
); | ||
MyClass( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g = ((»() -> 1«)) | ||
); | ||
|
||
MyEnum.MyEnumVariant( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
»() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
((»() -> 1«)) | ||
); | ||
MyEnum.MyEnumVariant( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g = ((»() -> 1«)) | ||
); | ||
|
||
myFunction( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
»() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
((»() -> 1«)) | ||
); | ||
myFunction( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g = ((»() -> 1«)) | ||
); | ||
|
||
mySegment1( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
»() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
((»() -> 1«)) | ||
); | ||
mySegment1( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
f = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
g = ((»() -> 1«)) | ||
); | ||
|
||
callableType( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
»() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
((»() -> 1«)) | ||
); | ||
callableType( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
p = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
q = ((»() -> 1«)) | ||
); | ||
|
||
blockLambda( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
»() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
((»() -> 1«)) | ||
); | ||
blockLambda( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
p = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
q = ((»() -> 1«)) | ||
); | ||
|
||
expressionLambda( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
»() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
((»() -> 1«)) | ||
); | ||
expressionLambda( | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
p = »() {}«, | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
q = ((»() -> 1«)) | ||
); | ||
} |
20 changes: 20 additions & 0 deletions
20
...ces/validation/other/expressions/lambdas/context/assigned to unresolved parameter.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,20 @@ | ||
package tests.validation.other.expressions.lambdas.context.assignedToUnresolvedParameter | ||
|
||
fun myFunction() | ||
|
||
pipeline unresolvedParameter { | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
myFunction(»() {}«); | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
myFunction(»() -> 1«); | ||
|
||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
myFunction(unresolved = »() {}«); | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
myFunction(unresolved = »() -> 1«); | ||
|
||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
unresolved(»() {}«); | ||
// $TEST$ no error "A lambda must be assigned to a typed parameter." | ||
unresolved(»() -> 1«); | ||
} |
Oops, something went wrong.