Skip to content

Commit

Permalink
Update query NonContextual type for map types.
Browse files Browse the repository at this point in the history
  • Loading branch information
SasinduDilshara committed Sep 19, 2022
1 parent b592741 commit d3dbd02
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,8 @@ public enum DiagnosticErrorCode implements DiagnosticCode {
UNSUPPORTED_RESOURCE_ACCESS_REST_SEGMENT_TYPE("BCE4032", "unsupported.resource.access.rest.segment.type"),
INVALID_RESOURCE_METHOD_RETURN_TYPE("BCE4033", "invalid.resource.method.return.type"),
OUT_OF_RANGE("BCE4034", "numeric.literal.out.of.range"),
INCOMPATIBLE_QUERY_CONSTRUCT_TYPE("BCE4035", "invalid.error.query.construct.type")
INCOMPATIBLE_QUERY_CONSTRUCT_TYPE("BCE4035", "invalid.error.query.construct.type"),
INCOMPATIBLE_QUERY_CONSTRUCT_MAP_TYPE("BCE4036", "invalid.error.query.construct.map.type");
;

private String diagnosticId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6300,7 +6300,8 @@ private BType getNonContextualQueryType(BType staticType, BType basicType, Locat
case TypeTags.STREAM:
return symTable.streamType;
case TypeTags.MAP:
return symTable.mapType;
dlog.error(pos, INCOMPATIBLE_QUERY_CONSTRUCT_MAP_TYPE);
return symTable.semanticError;
case TypeTags.XML:
if (types.isSubTypeOfBaseType(staticType, symTable.xmlType.tag)) {
return new BXMLType(staticType, null);
Expand All @@ -6315,8 +6316,6 @@ private BType getNonContextualQueryType(BType staticType, BType basicType, Locat
case TypeTags.TUPLE:
case TypeTags.OBJECT:
return new BArrayType(staticType);
default:
return symTable.semanticError;
}
dlog.error(pos, INCOMPATIBLE_QUERY_CONSTRUCT_TYPE, staticType, basicType);
return symTable.semanticError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,9 @@ error.invalid.error.detail.type=\
error.invalid.error.query.construct.type=\
incompatible type ''{0}'', expected a construct type of ''{1}''

error.invalid.error.query.construct.map.type=\
query expression that constructs a mapping must start with the map keyword

error.error.detail.arg.not.named.arg=\
error detail argument must be passed as named arguments

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public Object[][] dataProvider() {
{"createVariableInQueryAction1.json"},
{"createVariableInQueryAction2.json"},
{"createVariableInQueryAction3.json"},
{"createVariableInQueryAction4.json"},

// Tuple related
{"createVariableWithTuple1.json"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"character": 4
}
},
"newText": "string[] listResult = "
"newText": "int[] listResult = "
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
"character": 4
}
},
"newText": "(xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text)[] listResult = "
"newText": "xml<xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text> xmlResult = "
}
]
],
"resolvable": false
}
]
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public function func() {
xml x1 = xml `<book>The Lost World</book>`;
from xml element in x1 select element.toBalString();
int[] x1 = [1, 2, 3, 4, 5];
from int element in x1 select element;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,16 @@ public void testKeyLessTableWithReturnTable() {
Assert.assertTrue((Boolean) returnValues);
}

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

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

@Test(description = "Test negative scenarios for query expr with query construct type")
public void testNegativeScenarios() {
int index = 0;
Expand Down Expand Up @@ -306,6 +312,16 @@ public void testNegativeScenarios() {
" type of 'table<Employee> key(name)'", 463, 41);
validateError(negativeResult, index++, "incompatible type 'table<Employee> key(name)'," +
" expected a construct type of 'table<Employee> key(name)'", 464, 41);
validateError(negativeResult, index++, "query expression that constructs a mapping must " +
"start with the map keyword", 468, 36);
validateError(negativeResult, index++, "query expression that constructs a mapping must " +
"start with the map keyword", 469, 36);
validateError(negativeResult, index++, "query expression that constructs a mapping must " +
"start with the map keyword", 470, 36);
validateError(negativeResult, index++, "incompatible type in select clause: expected " +
"[string,any|error], found 'int'", 471, 40);
validateError(negativeResult, index++, "incompatible type in select clause: expected " +
"[string,any|error], found 'record {| int A; |}'", 472, 40);
Assert.assertEquals(negativeResult.getErrorCount(), index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,12 @@ function testQueryConstructWithInvalidStaticType() {
var _ = from Employee e in t select 1;
var _ = from Employee e in t select ["name", 35000];
var _ = from Employee e in t select t;

map<int> m = {"a": 1, "b": 2};

var _ = from var i in m select ["A",1];
var _ = from var i in m select 1;
var _ = from var i in m select {"A": 1};
var _ = map from var i in m select 1;
var _ = map from var i in m select {"A": 1};
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ function testConstructTablesWithRecords() {
assertEqual(a3.toString(), "[{\"name\":\"John\"},{\"name\":\"Jane\"}]");
}

function testConstructMapsWithTuples() {
map<int> a = {"a": 1, "b": 2};

var cm = map from var i in a select ["A",1];
assertTrue(cm is map<int>);
map<int> cm2 = cm;
assertEqual(cm2, {"A": 1});
}

function testInnerJoinAndLimitReturnStream() returns boolean {
boolean testPassed = true;

Expand Down

0 comments on commit d3dbd02

Please sign in to comment.