-
Notifications
You must be signed in to change notification settings - Fork 736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix NPE within annotation attachments #42762
base: master
Are you sure you want to change the base?
Conversation
@@ -4683,10 +4683,12 @@ private void validateAnnotationAttachmentExpr(BLangAnnotationAttachment annAttac | |||
} | |||
|
|||
if (annAttachmentNode.expr != null) { | |||
data.commonAnalyzerData.withinAnnotationExpr = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data.commonAnalyzerData.withinAnnotationExpr = true; | |
boolean prevWithinAnnotationExpr = data.commonAnalyzerData.withinAnnotationExpr; | |
data.commonAnalyzerData.withinAnnotationExpr = true; |
this.typeChecker.checkExpr(annAttachmentNode.expr, data.env, | ||
referredAnnotType.tag == | ||
TypeTags.ARRAY ? ((BArrayType) referredAnnotType).eType : annotType, data.prevEnvs, | ||
data.commonAnalyzerData); | ||
data.commonAnalyzerData.withinAnnotationExpr = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the previous value of the withinAnnotationExpr
in here.
@@ -3182,6 +3182,9 @@ public void visit(BLangSimpleVarRef varRefExpr, AnalyzerData data) { | |||
// TODO: call to isInLocallyDefinedRecord() is a temporary fix done to disallow local var references in | |||
// locally defined record type defs. This check should be removed once local var referencing is supported. | |||
if (((symbol.tag & SymTag.VARIABLE) == SymTag.VARIABLE)) { | |||
if (data.commonAnalyzerData.withinAnnotationExpr && varName.getValue().equals("self")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the constant value defined for self
keyword.
|
||
public function prefetchBooks() { | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for objects and service type definitions as well.
@@ -3182,6 +3182,9 @@ public void visit(BLangSimpleVarRef varRefExpr, AnalyzerData data) { | |||
// TODO: call to isInLocallyDefinedRecord() is a temporary fix done to disallow local var references in | |||
// locally defined record type defs. This check should be removed once local var referencing is supported. | |||
if (((symbol.tag & SymTag.VARIABLE) == SymTag.VARIABLE)) { | |||
if (data.commonAnalyzerData.withinAnnotationExpr && varName.getValue().equals("self")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this is not correct. Before reaching this logic, we check for self
within the main scope and set the symbol for self, which means we are allowing the self variable within that scope. This is not correct. At line 3171(lookupMainSpaceSymbolInPackage
), when checking for the symbol within the scope, we should not see self for this annotation scope.
What we did here is set the symbol of the variable and then handle it as a special case.
@@ -7169,6 +7169,7 @@ public static class CommonAnalyzerData { | |||
boolean breakToParallelQueryEnv = false; | |||
int letCount = 0; | |||
boolean nonErrorLoggingCheck = false; | |||
boolean withinAnnotationExpr = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do not define self
within the annotation scope, there is no need to define a special variable for it.
Purpose
$tilte
Fixes #41038
Approach
Samples
Remarks
Check List