Open
Conversation
# Conflicts: # arrow-reflect-annotations/src/main/kotlin/arrow/meta/Meta.kt # arrow-reflect-annotations/src/main/kotlin/arrow/meta/MetaContext.kt # arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt # arrow-reflect-compiler-plugin/src/main/kotlin/arrow/reflect/compiler/plugin/fir/checkers/FirMetaAdditionalCheckersExtension.kt # arrow-reflect-compiler-plugin/src/main/kotlin/arrow/reflect/compiler/plugin/fir/transformers/FirMetaTransformer.kt
# Conflicts: # arrow-reflect-annotations/src/main/kotlin/MetaModule.kt # arrow-reflect-compiler-plugin/src/main/kotlin/arrow/reflect/compiler/plugin/fir/checkers/FirMetaAdditionalCheckersExtension.kt # arrow-reflect-compiler-plugin/src/testGenerated/arrow/reflect/compiler/plugin/runners/DiagnosticTestGenerated.java
nomisRev
approved these changes
Jan 16, 2023
Member
nomisRev
left a comment
There was a problem hiding this comment.
LGTM, but I am missing expertise to review all changes in this PR.
|
|
||
| @Meta | ||
| @Target(AnnotationTarget.FUNCTION) | ||
| annotation class DisallowLambdaCapture(val msg: String = "") { |
Member
There was a problem hiding this comment.
Would this not be more precise as msg: String??
Comment on lines
+30
to
+32
| contract { | ||
| callsInPlace(f, InvocationKind.EXACTLY_ONCE) | ||
| } |
Member
There was a problem hiding this comment.
Not sure where this is checked in DisallowLambdaCapture.kt? 🤔
Member
|
I will review it too, sorry I miss it! |
JavierSegoviaCordoba
approved these changes
Jan 22, 2023
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
@DisallowLambdaCapturemacro is an annotation that can be applied to functions. It checks that functions annotated with@DisallowLambdaCaptureare not called inside a non-inline anonymous function that captures variables. If it finds such a call, it will report an error with a message specified in the@DisallowLambdaCaptureannotation or a default message if the msg parameter is not specified.To implement this macro, the
DisallowLambdaCapturecompanion object extends theMeta.Checker.Expressioninterface and overrides thecheckmethod. If present, this method first retrieves the msg argument of the DisallowLambdaCapture annotation. It then filters the declarations in the current scope to find any non-inline anonymous functions and checks if any of these functions capture variables. If it finds a function that captures variables and the function being checked is annotated with DisallowLambdaCapture, it reports an error with the specified message.The DisallowLambdaCapture macro can be helpful in cases where you want to ensure that certain functions are only called in a context where variable capture is not allowed. This can be useful for avoiding unintended side effects or enforcing a certain code style. For example, you might use this macro to disallow calling functions that modify the global state inside anonymous functions to ensure that the state changes are properly isolated and not leaked through the lambda capture.