Skip to content

Commit

Permalink
Remove object readonly check for annotation values
Browse files Browse the repository at this point in the history
  • Loading branch information
KRVPerera committed Jun 17, 2020
1 parent 93e74ca commit 5342dcd
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1361,8 +1364,22 @@ private boolean isValidAnnotationType(BType type) {

switch (type.tag) {
case TypeTags.MAP:
BType constraintType = ((BMapType) type).constraint;
return isAnyDataOrReadOnlyTypeSkippingObjectType(constraintType);
case TypeTags.RECORD:
return types.isAssignable(type, symTable.anydataOrReadOnlyMapType);
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;
if ((elementType.tag == TypeTags.MAP) || (elementType.tag == TypeTags.RECORD)) {
Expand All @@ -1374,6 +1391,57 @@ private boolean isValidAnnotationType(BType type) {
return types.isAssignable(type, symTable.trueType);
}

private boolean isAnyDataOrReadOnlyTypeSkippingObjectType(BType type) {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public class SymbolTable {
public final BType semanticError = new BType(TypeTags.SEMANTIC_ERROR, null);
public final BType nullSet = new BType(TypeTags.NULL_SET, null);
public final BUnionType anydataOrReadOnlyType = BUnionType.create(null, anydataType, readonlyType);
public final BType anydataOrReadOnlyMapType = new BMapType(TypeTags.MAP, anydataOrReadOnlyType, null);

public BType streamType = new BStreamType(TypeTags.STREAM, anydataType, null, null);
public BType tableType = new BTableType(TypeTags.TABLE, anydataType, null);
Expand Down

0 comments on commit 5342dcd

Please sign in to comment.