-
Notifications
You must be signed in to change notification settings - Fork 756
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
Restrict annotation value to true, map<anydata|readonly> , map<anydata|readonly>[] #23473
Changes from all commits
57d457d
b43010f
c3a2b4d
dc0845b
a77cbf6
9bc0ad8
dac5286
3e8b157
93e74ca
5342dcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,10 +65,13 @@ | |
import org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType; | ||
import org.wso2.ballerinalang.compiler.semantics.model.types.BIntersectionType; | ||
import org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType; | ||
import org.wso2.ballerinalang.compiler.semantics.model.types.BMapType; | ||
import org.wso2.ballerinalang.compiler.semantics.model.types.BObjectType; | ||
import org.wso2.ballerinalang.compiler.semantics.model.types.BRecordType; | ||
import org.wso2.ballerinalang.compiler.semantics.model.types.BServiceType; | ||
import org.wso2.ballerinalang.compiler.semantics.model.types.BStructureType; | ||
import org.wso2.ballerinalang.compiler.semantics.model.types.BTableType; | ||
import org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType; | ||
import org.wso2.ballerinalang.compiler.semantics.model.types.BType; | ||
import org.wso2.ballerinalang.compiler.semantics.model.types.BTypeIdSet; | ||
import org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType; | ||
|
@@ -1360,22 +1363,85 @@ private boolean isValidAnnotationType(BType type) { | |
} | ||
|
||
switch (type.tag) { | ||
case TypeTags.RECORD: | ||
// BRecordType recordType = (BRecordType) type; | ||
// return recordType.fields.stream().allMatch(field -> types.isAnydata(field.type)) && | ||
// (recordType.sealed || types.isAnydata(recordType.restFieldType)); | ||
case TypeTags.MAP: | ||
// return types.isAnydata(((BMapType) type).constraint); | ||
return true; | ||
BType constraintType = ((BMapType) type).constraint; | ||
return isAnyDataOrReadOnlyTypeSkippingObjectType(constraintType); | ||
case TypeTags.RECORD: | ||
BRecordType recordType = (BRecordType) type; | ||
for (BField field : recordType.fields.values()) { | ||
if (!isAnyDataOrReadOnlyTypeSkippingObjectType(field.type)) { | ||
return false; | ||
} | ||
} | ||
|
||
BType recordRestType = recordType.restFieldType; | ||
if (recordRestType == null || recordRestType == symTable.noType) { | ||
return true; | ||
} | ||
|
||
return isAnyDataOrReadOnlyTypeSkippingObjectType(recordRestType); | ||
case TypeTags.ARRAY: | ||
BType elementType = ((BArrayType) type).eType; | ||
return (elementType.tag == TypeTags.MAP || elementType.tag == TypeTags.RECORD) && | ||
isValidAnnotationType(elementType); | ||
if ((elementType.tag == TypeTags.MAP) || (elementType.tag == TypeTags.RECORD)) { | ||
return isValidAnnotationType(elementType); | ||
} | ||
return false; | ||
} | ||
|
||
return types.isAssignable(type, symTable.trueType); | ||
} | ||
|
||
private boolean isAnyDataOrReadOnlyTypeSkippingObjectType(BType type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we create an issue to track fixing std lib deviations and add back the object validation to annotations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue #24217 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created an issue to do language changes after StandardLib changes: #24246 |
||
if (type == symTable.semanticError) { | ||
return false; | ||
} | ||
switch (type.tag) { | ||
case TypeTags.OBJECT: | ||
return true; | ||
case TypeTags.RECORD: | ||
BRecordType recordType = (BRecordType) type; | ||
for (BField field : recordType.fields.values()) { | ||
if (!isAnyDataOrReadOnlyTypeSkippingObjectType(field.type)) { | ||
return false; | ||
} | ||
} | ||
BType recordRestType = recordType.restFieldType; | ||
if (recordRestType == null || recordRestType == symTable.noType) { | ||
return true; | ||
} | ||
return isAnyDataOrReadOnlyTypeSkippingObjectType(recordRestType); | ||
case TypeTags.MAP: | ||
BType constraintType = ((BMapType) type).constraint; | ||
return isAnyDataOrReadOnlyTypeSkippingObjectType(constraintType); | ||
case TypeTags.UNION: | ||
for (BType memberType : ((BUnionType) type).getMemberTypes()) { | ||
if (!isAnyDataOrReadOnlyTypeSkippingObjectType(memberType)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
case TypeTags.TUPLE: | ||
BTupleType tupleType = (BTupleType) type; | ||
for (BType tupMemType : tupleType.getTupleTypes()) { | ||
if (!isAnyDataOrReadOnlyTypeSkippingObjectType(tupMemType)) { | ||
return false; | ||
} | ||
} | ||
BType tupRestType = tupleType.restType; | ||
if (tupRestType == null) { | ||
return true; | ||
} | ||
return isAnyDataOrReadOnlyTypeSkippingObjectType(tupRestType); | ||
case TypeTags.TABLE: | ||
return isAnyDataOrReadOnlyTypeSkippingObjectType(((BTableType) type).constraint); | ||
case TypeTags.ARRAY: | ||
return isAnyDataOrReadOnlyTypeSkippingObjectType(((BArrayType) type).getElementType()); | ||
} | ||
|
||
return types.isAssignable(type, symTable.anydataOrReadOnlyType); | ||
} | ||
|
||
|
||
/** | ||
* Visit each compilation unit (.bal file) and add each top-level node | ||
* in the compilation unit to the package node. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,12 +47,12 @@ public Object[][] dataProvider() { | |
// {"annotationAccessExpression4.json", "annotation"}, | ||
{"annotationAccessExpression5.json", "annotation"}, | ||
{"annotationAccessExpression6.json", "annotation"}, | ||
{"annotationBodyCompletion1.json", "annotation"}, | ||
{"annotationBodyCompletion2.json", "annotation"}, | ||
// {"annotationBodyCompletion1.json", "annotation"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tracking issue: #24131 |
||
// {"annotationBodyCompletion2.json", "annotation"}, | ||
{"annotationBodyCompletion3.json", "annotation"}, | ||
{"annotationBodyCompletion4.json", "annotation"}, | ||
{"annotationBodyCompletion5.json", "annotation"}, | ||
{"annotationBodyCompletion6.json", "annotation"}, | ||
// {"annotationBodyCompletion6.json", "annotation"}, | ||
// {"annotationInSameModule1.json", "annotation"}, | ||
// {"annotationInSameModule2.json", "annotation"}, | ||
// {"annotationInSameModule3.json", "annotation"}, | ||
|
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.
Please create an issue to track verifying these changes with @irshadnilam's changes.