Skip to content

Commit

Permalink
Merge pull request #40237 from ballerina-platform/revert-38120-issue-…
Browse files Browse the repository at this point in the history
…#36543
  • Loading branch information
pcnfernando committed Apr 17, 2023
2 parents 9d7c3ef + 46d79cc commit ec44da1
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import org.wso2.ballerinalang.compiler.semantics.model.symbols.BResourceFunction;
import org.wso2.ballerinalang.compiler.semantics.model.symbols.BResourcePathSegmentSymbol;
import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol;
import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeDefinitionSymbol;
import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol;
import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol;
import org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol;
Expand Down Expand Up @@ -2894,14 +2893,7 @@ public void visit(BLangSimpleVarRef varRefExpr, AnalyzerData data) {
actualType = varSym.type;
markAndRegisterClosureVariable(symbol, varRefExpr.pos, data.env, data);
} else if ((symbol.tag & SymTag.TYPE_DEF) == SymTag.TYPE_DEF) {
if (symbol.kind == SymbolKind.TYPE_DEF) {
BTypeDefinitionSymbol typeDefSym = (BTypeDefinitionSymbol) symbol;
actualType = symbol.type.tag == TypeTags.TYPEDESC ? typeDefSym.referenceType
: new BTypedescType(typeDefSym.referenceType, null);
} else {
actualType = symbol.type.tag == TypeTags.TYPEDESC ? symbol.type
: new BTypedescType(symbol.type, null);
}
actualType = symbol.type.tag == TypeTags.TYPEDESC ? symbol.type : new BTypedescType(symbol.type, null);
varRefExpr.symbol = symbol;
} else if ((symbol.tag & SymTag.CONSTANT) == SymTag.CONSTANT) {
BConstantSymbol constSymbol = (BConstantSymbol) symbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.ballerinalang.model.TreeBuilder;
import org.ballerinalang.model.tree.NodeKind;
import org.ballerinalang.model.types.IntersectableReferenceType;
import org.ballerinalang.model.types.TypeKind;
import org.ballerinalang.util.diagnostic.DiagnosticErrorCode;
import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog;
import org.wso2.ballerinalang.compiler.semantics.analyzer.Types;
Expand Down Expand Up @@ -683,10 +682,6 @@ private BType getConstraintTypeIfNotError(BType type) {
return type;
}

if (type.getKind() == TypeKind.TYPEREFDESC) {
return ((BTypedescType) (Types.getReferredType(type))).constraint;
}

return ((BTypedescType) type).constraint;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.ballerina.runtime.api.PredefinedTypes;
import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.creators.ValueCreator;
import io.ballerina.runtime.api.types.AnnotatableType;
import io.ballerina.runtime.api.types.RecordType;
import io.ballerina.runtime.api.types.Type;
import io.ballerina.runtime.api.utils.StringUtils;
Expand All @@ -29,7 +28,6 @@
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.api.values.BFunctionPointer;
import io.ballerina.runtime.api.values.BFuture;
import io.ballerina.runtime.api.values.BMap;
import io.ballerina.runtime.api.values.BMapInitialValueEntry;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.api.values.BStream;
Expand All @@ -42,7 +40,6 @@
import io.ballerina.runtime.internal.types.BRecordType;
import io.ballerina.runtime.internal.types.BStreamType;
import io.ballerina.runtime.internal.types.BTupleType;
import io.ballerina.runtime.internal.types.BTypeReferenceType;
import io.ballerina.runtime.internal.values.ArrayValue;
import io.ballerina.runtime.internal.values.ArrayValueImpl;
import io.ballerina.runtime.internal.values.BmpStringValue;
Expand Down Expand Up @@ -347,24 +344,6 @@ public static Object getWithUnion(Object x, BTypedesc y) {
return ErrorCreator.createError(StringUtils.fromString("Error!"), StringUtils.fromString("Union typedesc"));
}

public static BMap<BString, Object> getAnnotationValue(BTypedesc y) {
return ((BTypeReferenceType) y.getDescribingType()).getAnnotations();
}

public static Object getAnnotationValue2(Object value, BTypedesc y, BString annotationName, int min, int max) {
Type describingType = y.getDescribingType();
BMap<BString, Object> annotations = ((AnnotatableType) describingType).getAnnotations();
if (annotations.containsKey(annotationName)) {
Object annotValue = annotations.get(annotationName);
Long minValue = (Long) ((BMap) annotValue).get(StringUtils.fromString("minValue"));
Long maxValue = (Long) ((BMap) annotValue).get(StringUtils.fromString("maxValue"));
if (minValue == min && maxValue == max) {
return value;
}
}
return ErrorCreator.createError(StringUtils.fromString("Validation failed for " + annotationName + "."));
}

public static Object clientGetWithUnion(BObject client, Object x, BTypedesc y) {
return getWithUnion(x, y);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ public void testAnnotOnBoundMethod() {
BRunUtil.invoke(result, "testAnnotOnBoundMethod");
}

@Test
public void testAnnotationWithReferredType() {
BRunUtil.invoke(result, "testAnnotationsOnTypeRefTypes");
}

@Test
public void testParamAnnotAttachmentsViaBir() {
BLangPackage bLangPackage = (BLangPackage) birTestResult.getAST();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,9 @@ public void testStampNegativeTest() {
"incompatible types: expected 'typedesc<anydata>', found 'typedesc<EmployeeObject>'",
87, 63);
BAssertUtil.validateError(compileResult, index++,
"incompatible types: expected 'typedesc<anydata>', found 'typedesc<AnyMap>'", 95, 54);
"incompatible types: expected 'typedesc<anydata>', found 'typedesc<map>'", 95, 54);
BAssertUtil.validateError(compileResult, index++,
"incompatible types: expected 'anydata', found 'ExtendedEmployee'", 103, 34);
BAssertUtil.validateError(compileResult, index++,
"incompatible types: expected 'typedesc<anydata>', found 'typedesc<MapAny>'", 114, 51);
BAssertUtil.validateError(compileResult, index++,
"incompatible types: expected 'typedesc<anydata>', found 'typedesc<AnyMap>'", 115, 51);
Assert.assertEquals(index, compileResult.getErrorCount());
}

Expand All @@ -113,11 +109,11 @@ public void testObjectNegativeTest() {
BAssertUtil.validateError(objectNegativeTestCompileResult, index++,
"incompatible types: expected 'anydata', found 'PersonObj'", 106, 51);
BAssertUtil.validateError(objectNegativeTestCompileResult, index++,
"incompatible types: expected 'typedesc<anydata>', found 'typedesc<AnyMap>'", 106, 54);
"incompatible types: expected 'typedesc<anydata>', found 'typedesc<map>'", 106, 54);
BAssertUtil.validateError(objectNegativeTestCompileResult, index++,
"incompatible types: expected 'anydata', found 'PersonObj'", 113, 48);
BAssertUtil.validateError(objectNegativeTestCompileResult, index++,
"incompatible types: expected 'typedesc<anydata>', found 'typedesc<AnyArray>'", 113, 51);
"incompatible types: expected 'typedesc<anydata>', found 'typedesc<any[]>'", 113, 51);
BAssertUtil.validateError(objectNegativeTestCompileResult, index++,
"incompatible types: expected 'anydata', found 'PersonObj'", 120, 58);
BAssertUtil.validateError(objectNegativeTestCompileResult, index++,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ public Object[][] getFuncNames() {
{"testVarRefInMapConstraint"},
{"testVarRefUseInMultiplePlaces"},
{"testSimpleTypes"},
{"testReferredTypes"},
{"testUnionTypes"},
{"testArrayTypes"},
{"testXML"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ public void testDependentlyTypedFunctionWithInferredTypedescValueNegative() {
validateError(negativeResult, index++, INVALID_RETURN_TYPE_ERROR, 54, 66);
validateError(negativeResult, index++, INVALID_RETURN_TYPE_ERROR, 56, 49);
validateError(negativeResult, index++,
"incompatible types: expected 'xml:Comment', found 'xml<XmlComment>'", 65, 21);
"incompatible types: expected 'xml:Comment', found 'xml<xml:Comment>'", 65, 21);
validateError(negativeResult, index++,
"incompatible types: expected 'xml<xml:Element>', found 'xml<XmlComment>'", 66, 26);
"incompatible types: expected 'xml<xml:Element>', found 'xml<xml:Comment>'", 66, 26);
validateError(negativeResult, index++,
"incompatible types: expected 'xml<xml:Text>', found 'xml<XmlElement>'", 67, 23);
"incompatible types: expected 'xml<xml:Text>', found 'xml<xml:Element>'", 67, 23);
validateError(negativeResult, index++,
"incompatible types: expected 'xml<xml:Comment>', found 'xml<XmlElement>'", 68, 26);
"incompatible types: expected 'xml<xml:Comment>', found 'xml<xml:Element>'", 68, 26);
validateError(negativeResult, index++,
"incompatible types: expected 'typedesc<(xml:Element|xml:Comment)>', found 'typedesc<XmlText>'",
"incompatible types: expected 'typedesc<(xml:Element|xml:Comment)>', found 'typedesc<xml:Text>'",
69, 38);
validateError(negativeResult, index++, "cannot infer the 'typedesc' argument for parameter 'td' with " +
"'boolean?' as the contextually-expected type mapping to return type '(td|boolean)?'", 78, 18);
Expand Down Expand Up @@ -165,7 +165,7 @@ public void testDependentlyTypedFunctionWithInferredTypedescValueNegative() {
validateError(negativeResult, index++, "incompatible types: expected 'stream<int>?', found 'typedesc<int>'",
145, 67);
validateError(negativeResult, index++, "incompatible types: expected '(stream<boolean>|readonly)', found '" +
"(readonly|IntStream|handle)'", 146, 34);
"(readonly|stream<int>|handle)'", 146, 34);
validateError(negativeResult, index++, "cannot infer the 'typedesc' argument for parameter 'td' with " +
"'(readonly|handle)' as the contextually-expected type mapping to return type '(readonly|td|handle)'",
147, 25);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ public void testNegative() {
10, 24);
validateError(compileResult, index++, "missing key expr in member access expr", 10, 31);
validateError(compileResult, index++, "incompatible types: expected 'typedesc<readonly>', found " +
"'typedesc<IntArray>'", 21, 28);
"'typedesc<int[]>'", 21, 28);
validateError(compileResult, index++, "incompatible types: expected 'typedesc<(string[]|boolean[])>', found " +
"'typedesc<ImmutableIntArray>'", 22, 38);
validateError(compileResult, index++, "incompatible types: expected 'typedesc<string>', " +
"found 'typedesc<ImmutableIntArray>'", 23, 26);
validateError(compileResult, index++, "incompatible types: expected 'typedesc<string[]>', found " +
"'typedesc<Foo>'", 24, 28);
"'typedesc<\"foo\">'", 24, 28);
validateError(compileResult, index++, "incompatible types: expected 'typedesc<string>', found " +
"'typedesc<FooBar>'", 25, 26);
"'typedesc<\"foo\"|1>'", 25, 26);
validateError(compileResult, index++, "incompatible types: expected 'typedesc<string>', found " +
"'typedesc<FunctionTypeOne>'", 26, 26);
"'typedesc<function (int) returns (string)>'", 26, 26);
validateError(compileResult, index++, "incompatible types: expected 'typedesc<function (int) returns (string)" +
">', found 'typedesc<FunctionTypeTwo>'", 27, 51);
">', found 'typedesc<function () returns (string)>'", 27, 51);
Assert.assertEquals(compileResult.getErrorCount(), index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,67 +59,6 @@ function getAnonymousTupleAnnotations(typedesc<any> obj, string annotName) retur
name: "getAnonymousTupleAnnotations"
} external;

type AnnotationRecord record {|
int minValue;
int maxValue;
|};

annotation AnnotationRecord BarAnnotation on type;
annotation AnnotationRecord BarAnnotation2 on type;

@BarAnnotation {
minValue: 18,
maxValue: 36
}
type Bar int|float;
type Bar2 int|float;

@BarAnnotation2 {
minValue: 18,
maxValue: 36
}
type Bar3 Bar4;
type Bar4 Bar2;
type Bar5 Bar;

function testAnnotationsOnTypeRefTypes() {
var f1 = function (typedesc td) returns AnnotationRecord? {
return td.@BarAnnotation;
};

AnnotationRecord? 'annotation = f1(Bar);
assertTrue('annotation is AnnotationRecord);
AnnotationRecord rec = <AnnotationRecord> 'annotation;
assertEquality(rec.minValue, 18);
assertEquality(rec.maxValue, 36);

'annotation = f1(Bar2);
assertTrue('annotation is ());

var f2 = function (typedesc td) returns AnnotationRecord? {
return td.@BarAnnotation2;
};

'annotation = f2(Bar3);
assertTrue('annotation is AnnotationRecord);
rec = <AnnotationRecord> 'annotation;
assertEquality(rec.minValue, 18);
assertEquality(rec.maxValue, 36);

'annotation = f2(Bar4);
assertTrue('annotation is ());

'annotation = f1(Bar5);
assertTrue('annotation is ());

'annotation = f2(Bar5);
assertTrue('annotation is ());
}

function assertTrue(anydata actual) {
assertEquality(true, actual);
}

function assertEquality(anydata expected, anydata actual) {
if expected == actual {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,3 @@ function stampExtendedRecordToAnydata() returns anydata|error {

type AnyMap map<any>;
type JsonTypedesc typedesc<json>;
type MapAny AnyMap;

function stampAnydataArrayToXML() returns xml|error {
anydata[] anydataArray = [];
map<any>|error x = anydataArray.cloneWithType(MapAny);
map<any>|error y = anydataArray.cloneWithType(AnyMap);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,6 @@ type Employee record {

Person expPerson = {name: "John Doe", age: 20};

type Foo int|float;

type Foo2 Foo;

type AnnotationRecord record {|
int minValue;
int maxValue;
|};

annotation AnnotationRecord BarAnnotation on type;

@BarAnnotation {
minValue: 18,
maxValue: 36
}
type Foo3 int|float;

@BarAnnotation {
minValue: 12,
maxValue: 24
}
type Foo4 Foo;

// Test functions

Expand All @@ -73,26 +51,6 @@ function testSimpleTypes() {
assert(true, b);
}

function testReferredTypes() {
map<any> annotationMapValue = getAnnotationValue(Foo);
AnnotationRecord? 'annotation = <AnnotationRecord?> annotationMapValue["BarAnnotation"];
assert('annotation, ());

map<any> annotationMapValue2 = getAnnotationValue(Foo2);
AnnotationRecord? annotation2 = <AnnotationRecord?> annotationMapValue2["BarAnnotation"];
assert(annotation2, ());

map<any> annotationMapValue3 = getAnnotationValue(Foo3);
AnnotationRecord annotation3 = <AnnotationRecord> annotationMapValue3["BarAnnotation"];
assert(annotation3, {minValue: 18, maxValue: 36});
assertTrue(getAnnotationValue2(1, Foo3, "BarAnnotation", 18, 36) is anydata);

map<any> annotationMapValue4 = getAnnotationValue(Foo4);
AnnotationRecord annotation4 = <AnnotationRecord> annotationMapValue4["BarAnnotation"];
assert(annotation4, <AnnotationRecord> {minValue: 12, maxValue: 24});
assertTrue(getAnnotationValue2(1, Foo4, "BarAnnotation", 12, 24) is anydata);
}

function testRecordVarRef() {
Person p = getRecord();
assert(expPerson, p);
Expand Down Expand Up @@ -283,19 +241,6 @@ function getValue(typedesc<int|float|decimal|string|boolean> td) returns td = @j
paramTypes: ["io.ballerina.runtime.api.values.BTypedesc"]
} external;

function getAnnotationValue(typedesc<Foo|Foo2> y) returns map<any> =
@java:Method {
'class: "org.ballerinalang.nativeimpl.jvm.tests.VariableReturnType",
name: "getAnnotationValue"
} external;

function getAnnotationValue2(anydata value, typedesc<anydata> td = <>, string annotationName = "",
int min = 0, int max = 0) returns td|error =
@java:Method {
'class: "org.ballerinalang.nativeimpl.jvm.tests.VariableReturnType",
name: "getAnnotationValue2"
} external;

function getRecord(typedesc<anydata> td = Person) returns td = @java:Method {
'class: "org.ballerinalang.nativeimpl.jvm.tests.VariableReturnType",
name: "getRecord",
Expand Down Expand Up @@ -993,7 +938,3 @@ function assertSame(any|error expected, any|error actual) {
panic error("{AssertionError}", message = detail);
}
}

function assertTrue(anydata actual) {
assert(actual, true);
}

0 comments on commit ec44da1

Please sign in to comment.