Skip to content

Commit

Permalink
Remove unused validation of cast to imported anon type
Browse files Browse the repository at this point in the history
  • Loading branch information
MaryamZi committed May 7, 2021
1 parent 8be01a4 commit 1d11187
Showing 1 changed file with 0 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6780,8 +6780,6 @@ public void visit(BLangTypeConversionExpr conversionExpr) {
}

BType targetType = conversionExpr.targetType;
// validateIsNotCastToAnImportedAnonType(targetType == null ? conversionExpr.type : targetType);

conversionExpr.typeNode = rewrite(conversionExpr.typeNode, env);

conversionExpr.expr = rewriteExpr(conversionExpr.expr);
Expand Down Expand Up @@ -9815,96 +9813,6 @@ private BLangRecordLiteral rewriteMappingConstructor(BLangRecordLiteral mappingC
new BLangMapLiteral(pos, type, rewrittenFields);
}

/**
* This in intended to be a temporary validation to avoid casting to anonymous types from imported packages,
* because such casts can cause backward compatibility issues since anonymous type names can change per compilation.
* The current alternative in such a scenario is to cast to a compatible in-line type. For example, a cast to an
* anonymous record type can be replaced with a cast to a map type.
* If this is not possible due to some reason, we need to introduce an approach to uniquely identify anonymous
* types across compilations.
* See https://github.com/ballerina-platform/ballerina-lang/issues/28262.
*/
private void validateIsNotCastToAnImportedAnonType(BType targetType) {
validateIsNotCastToAnImportedAnonType(targetType, new HashSet<>());
}

private void validateIsNotCastToAnImportedAnonType(BType targetType, Set<BType> unresolvedTypes) {
if (!unresolvedTypes.add(targetType)) {
return;
}

switch (targetType.tag) {
case TypeTags.TABLE:
validateIsNotCastToAnImportedAnonType(((BTableType) targetType).constraint, unresolvedTypes);
return;
case TypeTags.TYPEDESC:
validateIsNotCastToAnImportedAnonType(((BTypedescType) targetType).constraint, unresolvedTypes);
return;
case TypeTags.STREAM:
validateIsNotCastToAnImportedAnonType(((BStreamType) targetType).constraint, unresolvedTypes);
return;
case TypeTags.MAP:
validateIsNotCastToAnImportedAnonType(((BMapType) targetType).constraint, unresolvedTypes);
return;
case TypeTags.INVOKABLE:
BInvokableType invokableType = (BInvokableType) targetType;
for (BType paramType : invokableType.paramTypes) {
validateIsNotCastToAnImportedAnonType(paramType, unresolvedTypes);
}

BType restType = invokableType.restType;
if (restType != null) {
validateIsNotCastToAnImportedAnonType(restType, unresolvedTypes);
}

BType retType = invokableType.retType;
if (retType != null) {
validateIsNotCastToAnImportedAnonType(retType, unresolvedTypes);
}
return;
case TypeTags.ARRAY:
validateIsNotCastToAnImportedAnonType(((BArrayType) targetType).eType, unresolvedTypes);
return;
case TypeTags.UNION:
for (BType memberType : ((BUnionType) targetType).getMemberTypes()) {
validateIsNotCastToAnImportedAnonType(memberType, unresolvedTypes);
}
return;
case TypeTags.INTERSECTION:
for (BType constituentType : ((BIntersectionType) targetType).getConstituentTypes()) {
validateIsNotCastToAnImportedAnonType(constituentType, unresolvedTypes);
}
return;
case TypeTags.ERROR:
validateIsNotCastToAnImportedAnonType(((BErrorType) targetType).detailType, unresolvedTypes);
return;
case TypeTags.TUPLE:
BTupleType tupleType = (BTupleType) targetType;
for (BType tupleMemberType : tupleType.tupleTypes) {
validateIsNotCastToAnImportedAnonType(tupleMemberType, unresolvedTypes);
}

BType tupleRestType = tupleType.restType;
if (tupleRestType != null) {
validateIsNotCastToAnImportedAnonType(tupleRestType, unresolvedTypes);
}
return;
case TypeTags.FUTURE:
BType constraint = ((BFutureType) targetType).constraint;
if (constraint != null) {
validateIsNotCastToAnImportedAnonType(constraint, unresolvedTypes);
}
return;
case TypeTags.RECORD:
case TypeTags.OBJECT:
if (Symbols.isFlagOn(targetType.flags, Flags.ANONYMOUS) &&
!targetType.tsymbol.pkgID.equals(env.enclPkg.packageID)) {
throw new IllegalStateException("Invalid cast to anonymous type imported from '" +
targetType.tsymbol.pkgID.toString() + "'");
}
}
}

protected void addTransactionInternalModuleImport() {
PackageID packageID = new PackageID(Names.BALLERINA_INTERNAL_ORG, Lists.of(Names.TRANSACTION),
Names.TRANSACTION_INTERNAL_VERSION);
Expand Down

0 comments on commit 1d11187

Please sign in to comment.