Skip to content

Commit

Permalink
Merge pull request #41131 from rdulmina/master
Browse files Browse the repository at this point in the history
Fix `map` keyword using as an identifier when it is followed by `<`
  • Loading branch information
rdulmina authored Aug 7, 2023
2 parents b8b78ca + b08e9fe commit fd18464
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4145,17 +4145,19 @@ private STNode parseQualifiedIdentifier(STNode identifier, boolean isInCondition
STToken colon = consume();
STNode varOrFuncName = consume();
return createQualifiedNameReferenceNode(identifier, colon, varOrFuncName);
case MAP_KEYWORD:
colon = consume();
STToken mapKeyword = consume();
STNode refName = STNodeFactory.createIdentifierToken(mapKeyword.text(), mapKeyword.leadingMinutiae(),
mapKeyword.trailingMinutiae(), mapKeyword.diagnostics());
return createQualifiedNameReferenceNode(identifier, colon, refName);
case COLON_TOKEN:
// specially handle cases where there are more than one colon.
addInvalidTokenToNextToken(errorHandler.consumeInvalidToken());
return parseQualifiedIdentifier(identifier, isInConditionalExpr);
default:
if (nextNextToken.kind == SyntaxKind.MAP_KEYWORD && peek(3).kind != SyntaxKind.LT_TOKEN) {
colon = consume();
STToken mapKeyword = consume();
STNode refName = STNodeFactory.createIdentifierToken(mapKeyword.text(),
mapKeyword.leadingMinutiae(), mapKeyword.trailingMinutiae(), mapKeyword.diagnostics());
return createQualifiedNameReferenceNode(identifier, colon, refName);
}

if (isInConditionalExpr) {
return ConditionalExprResolver.getSimpleNameRefNode(identifier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ public void testIncompleteQualifiedIdent() {

@Test
public void testInterveningWSNotAllowed() {
testFile("qualified-identifier/qualified_identifier_assert_08.bal",
testFile("qualified-identifier/qualified_identifier_source_08.bal",
"qualified-identifier/qualified_identifier_assert_08.json");
}

@Test
public void testMapTypeAfterColon() {
testFile("qualified-identifier/qualified_identifier_source_09.bal",
"qualified-identifier/qualified_identifier_assert_09.json");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
{
"kind": "FUNCTION_DEFINITION",
"hasDiagnostics": true,
"children": [
{
"kind": "LIST",
"children": [
{
"kind": "PUBLIC_KEYWORD",
"trailingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
}
]
}
]
},
{
"kind": "FUNCTION_KEYWORD",
"trailingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
}
]
},
{
"kind": "IDENTIFIER_TOKEN",
"value": "main"
},
{
"kind": "LIST",
"children": []
},
{
"kind": "FUNCTION_SIGNATURE",
"children": [
{
"kind": "OPEN_PAREN_TOKEN"
},
{
"kind": "LIST",
"children": []
},
{
"kind": "CLOSE_PAREN_TOKEN",
"trailingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
}
]
}
]
},
{
"kind": "FUNCTION_BODY_BLOCK",
"hasDiagnostics": true,
"children": [
{
"kind": "OPEN_BRACE_TOKEN",
"trailingMinutiae": [
{
"kind": "END_OF_LINE_MINUTIAE",
"value": "\n"
}
]
},
{
"kind": "LIST",
"hasDiagnostics": true,
"children": [
{
"kind": "INVALID_EXPRESSION_STATEMENT",
"hasDiagnostics": true,
"diagnostics": [
"ERROR_INVALID_EXPRESSION_STATEMENT"
],
"children": [
{
"kind": "QUALIFIED_NAME_REFERENCE",
"hasDiagnostics": true,
"children": [
{
"kind": "IDENTIFIER_TOKEN",
"value": "module1",
"leadingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
}
]
},
{
"kind": "COLON_TOKEN",
"hasDiagnostics": true,
"diagnostics": [
"ERROR_INTERVENING_WHITESPACES_ARE_NOT_ALLOWED"
],
"trailingMinutiae": [
{
"kind": "END_OF_LINE_MINUTIAE",
"value": "\n"
}
]
},
{
"kind": "IDENTIFIER_TOKEN",
"isMissing": true,
"hasDiagnostics": true,
"diagnostics": [
"ERROR_MISSING_IDENTIFIER"
]
}
]
},
{
"kind": "SEMICOLON_TOKEN",
"isMissing": true,
"hasDiagnostics": true,
"diagnostics": [
"ERROR_MISSING_SEMICOLON_TOKEN"
]
}
]
},
{
"kind": "LOCAL_VAR_DECL",
"children": [
{
"kind": "LIST",
"children": []
},
{
"kind": "TYPED_BINDING_PATTERN",
"children": [
{
"kind": "MAP_TYPE_DESC",
"children": [
{
"kind": "MAP_KEYWORD",
"leadingMinutiae": [
{
"kind": "END_OF_LINE_MINUTIAE",
"value": "\n"
},
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
}
]
},
{
"kind": "TYPE_PARAMETER",
"children": [
{
"kind": "LT_TOKEN"
},
{
"kind": "INT_TYPE_DESC",
"children": [
{
"kind": "INT_KEYWORD"
}
]
},
{
"kind": "GT_TOKEN",
"trailingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
}
]
}
]
}
]
},
{
"kind": "CAPTURE_BINDING_PATTERN",
"children": [
{
"kind": "IDENTIFIER_TOKEN",
"value": "m",
"trailingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
}
]
}
]
}
]
},
{
"kind": "EQUAL_TOKEN",
"trailingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
}
]
},
{
"kind": "MAPPING_CONSTRUCTOR",
"children": [
{
"kind": "OPEN_BRACE_TOKEN"
},
{
"kind": "LIST",
"children": []
},
{
"kind": "CLOSE_BRACE_TOKEN"
}
]
},
{
"kind": "SEMICOLON_TOKEN",
"trailingMinutiae": [
{
"kind": "END_OF_LINE_MINUTIAE",
"value": "\n"
}
]
}
]
}
]
},
{
"kind": "CLOSE_BRACE_TOKEN",
"trailingMinutiae": [
{
"kind": "END_OF_LINE_MINUTIAE",
"value": "\n"
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public function main() {
module1:

map<int> m = {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public List<String> skipList() {
"float_literal_source_07.bal",
"method_call_expr_source_03.bal",
"method_call_expr_source_05.bal",
"qualified_identifier_assert_08.bal",
"qualified_identifier_source_08.bal",
"conditional_expr_source_28.bal",
"resiliency_source_04.bal",
"record_type_def_source_14.bal",
Expand Down

0 comments on commit fd18464

Please sign in to comment.