Permalink
Browse files

syntax error when using anonymous struct in if-statement, fix #2746

(cherry picked from commit cf6153525597b6bdf1daabfbace230d7581069f4)
  • Loading branch information...
1 parent 923ea05 commit 7799ff019bb972f07b026b4a5867369edd7e396c @ignatov ignatov committed Aug 18, 2016
@@ -2435,7 +2435,7 @@ static boolean LiteralTypeExprInner(PsiBuilder b, int l) {
}
/* ********************************************************** */
- // (<<isModeOff "BLOCK?">> | <<isModeOn "PAR">> | <<prevIsArrayType>>) '{' ElementList? '}'
+ // (<<isModeOff "BLOCK?">> | <<isModeOn "PAR">> | <<prevIsType>>) '{' ElementList? '}'
public static boolean LiteralValue(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "LiteralValue")) return false;
boolean r, p;
@@ -2449,14 +2449,14 @@ public static boolean LiteralValue(PsiBuilder b, int l) {
return r || p;
}
- // <<isModeOff "BLOCK?">> | <<isModeOn "PAR">> | <<prevIsArrayType>>
+ // <<isModeOff "BLOCK?">> | <<isModeOn "PAR">> | <<prevIsType>>
private static boolean LiteralValue_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "LiteralValue_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = isModeOff(b, l + 1, "BLOCK?");
if (!r) r = isModeOn(b, l + 1, "PAR");
- if (!r) r = prevIsArrayType(b, l + 1);
+ if (!r) r = prevIsType(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
View
@@ -315,7 +315,7 @@ private LiteralTypeExprInner ::= StructType | ArrayOrSliceType | MapType
LiteralTypeExpr ::= LiteralTypeExprInner | TypeName
-LiteralValue ::= (<<isModeOff "BLOCK?">> | <<isModeOn "PAR">> | <<prevIsArrayType>>) '{' ElementList? '}' {pin=2}
+LiteralValue ::= (<<isModeOff "BLOCK?">> | <<isModeOn "PAR">> | <<prevIsType>>) '{' ElementList? '}' {pin=2}
private ElementList ::= E ( ',' E? )*
private E ::= <<withOn "PAR" Element>> | (!() Element) {recoverWhile=E_recover}
private E_recover ::= !('}'|',')
@@ -135,10 +135,10 @@ public static boolean isModeOff(@NotNull PsiBuilder builder_, @SuppressWarnings(
return getParsingModes(builder_).get(mode) == 0;
}
- public static boolean prevIsArrayType(@NotNull PsiBuilder builder_, @SuppressWarnings("UnusedParameters") int level) {
+ public static boolean prevIsType(@NotNull PsiBuilder builder_, @SuppressWarnings("UnusedParameters") int level) {
LighterASTNode marker = builder_.getLatestDoneMarker();
IElementType type = marker != null ? marker.getTokenType() : null;
- return type == GoTypes.ARRAY_OR_SLICE_TYPE || type == GoTypes.MAP_TYPE;
+ return type == GoTypes.ARRAY_OR_SLICE_TYPE || type == GoTypes.MAP_TYPE || type == GoTypes.STRUCT_TYPE;
}
public static boolean keyOrValueExpression(@NotNull PsiBuilder builder_, int level) {
@@ -0,0 +1,18 @@
+package main
+
+import (
+ "fmt"
+)
+
+func main() {
+ s := struct{ Username, Password string }{
+ "User",
+ "Password",
+ }
+
+ if s != struct{ Username, Password string }{} {
+ fmt.Println("yes")
+ } else {
+ fmt.Println("yes")
+ }
+}
@@ -0,0 +1,113 @@
+GO_FILE
+ PACKAGE_CLAUSE
+ PsiElement(package)('package')
+ PsiElement(identifier)('main')
+ IMPORT_LIST
+ IMPORT_DECLARATION
+ PsiElement(import)('import')
+ PsiElement(()('(')
+ IMPORT_SPEC
+ STRING_LITERAL
+ PsiElement(string)('"fmt"')
+ PsiElement())(')')
+ FUNCTION_DECLARATION
+ PsiElement(func)('func')
+ PsiElement(identifier)('main')
+ SIGNATURE
+ PARAMETERS
+ PsiElement(()('(')
+ PsiElement())(')')
+ BLOCK
+ PsiElement({)('{')
+ SIMPLE_STATEMENT
+ SHORT_VAR_DECLARATION
+ VAR_DEFINITION
+ PsiElement(identifier)('s')
+ PsiElement(:=)(':=')
+ COMPOSITE_LIT
+ STRUCT_TYPE
+ PsiElement(struct)('struct')
+ PsiElement({)('{')
+ FIELD_DECLARATION
+ FIELD_DEFINITION
+ PsiElement(identifier)('Username')
+ PsiElement(,)(',')
+ FIELD_DEFINITION
+ PsiElement(identifier)('Password')
+ TYPE
+ TYPE_REFERENCE_EXPRESSION
+ PsiElement(identifier)('string')
+ PsiElement(})('}')
+ LITERAL_VALUE
+ PsiElement({)('{')
+ ELEMENT
+ VALUE
+ STRING_LITERAL
+ PsiElement(string)('"User"')
+ PsiElement(,)(',')
+ ELEMENT
+ VALUE
+ STRING_LITERAL
+ PsiElement(string)('"Password"')
+ PsiElement(,)(',')
+ PsiElement(})('}')
+ IF_STATEMENT
+ PsiElement(if)('if')
+ SIMPLE_STATEMENT
+ LEFT_HAND_EXPR_LIST
+ CONDITIONAL_EXPR
+ REFERENCE_EXPRESSION
+ PsiElement(identifier)('s')
+ PsiElement(!=)('!=')
+ COMPOSITE_LIT
+ STRUCT_TYPE
+ PsiElement(struct)('struct')
+ PsiElement({)('{')
+ FIELD_DECLARATION
+ FIELD_DEFINITION
+ PsiElement(identifier)('Username')
+ PsiElement(,)(',')
+ FIELD_DEFINITION
+ PsiElement(identifier)('Password')
+ TYPE
+ TYPE_REFERENCE_EXPRESSION
+ PsiElement(identifier)('string')
+ PsiElement(})('}')
+ LITERAL_VALUE
+ PsiElement({)('{')
+ PsiElement(})('}')
+ BLOCK
+ PsiElement({)('{')
+ SIMPLE_STATEMENT
+ LEFT_HAND_EXPR_LIST
+ CALL_EXPR
+ REFERENCE_EXPRESSION
+ REFERENCE_EXPRESSION
+ PsiElement(identifier)('fmt')
+ PsiElement(.)('.')
+ PsiElement(identifier)('Println')
+ ARGUMENT_LIST
+ PsiElement(()('(')
+ STRING_LITERAL
+ PsiElement(string)('"yes"')
+ PsiElement())(')')
+ PsiElement(})('}')
+ ELSE_STATEMENT
+ PsiElement(else)('else')
+ BLOCK
+ PsiElement({)('{')
+ SIMPLE_STATEMENT
+ LEFT_HAND_EXPR_LIST
+ CALL_EXPR
+ REFERENCE_EXPRESSION
+ REFERENCE_EXPRESSION
+ PsiElement(identifier)('fmt')
+ PsiElement(.)('.')
+ PsiElement(identifier)('Println')
+ ARGUMENT_LIST
+ PsiElement(()('(')
+ STRING_LITERAL
+ PsiElement(string)('"yes"')
+ PsiElement())(')')
+ PsiElement(})('}')
+ PsiElement(})('}')
@@ -34,6 +34,7 @@ public GoParserTest() {
public void testIncompleteRanges() { doTest(false); }
public void testTorture() { doTest(true); }
public void testLiteralValues() { doTest(true); }
+ public void testLiteralValuesElse() { doTest(true); }
public void testIfComposite() { doTest(true); }
public void testArrayTypes() { doTest(true); }
public void testArrayTypesInRanges() { doTest(true); }

0 comments on commit 7799ff0

Please sign in to comment.