Skip to content

Commit

Permalink
Adding missing null-coalescing assignment operator(#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Jan 29, 2025
1 parent b3137ab commit 2343506
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ CONDITIONAL_ERROR="#error"[^\r\n]*
"!" { return emitToken( ONOT); }
"~" / [^"/"] { return emitToken( OCOMPLEMENT); }

"??=" { return emitToken( OQUEST_QUEST_ASSIGN);}
"??" { return emitToken( OQUEST_QUEST);}
"?" { return emitToken( OQUEST);}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/intellij/plugins/haxe/lang/parser/haxe.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
oMINUS_ASSIGN="-="
oMINUS="-"

oQUEST_QUEST_ASSIGN="??="
oQUEST_QUEST="??"
oQUEST="?"

Expand Down Expand Up @@ -198,7 +199,7 @@ private metaKeyWord ::= embeddedMeta | '@'
* after shiftRight so that it has priority.
*/
fake operator ::= ":" | ";" | "," |"." | "==" | "=" | "!=" | "!" | "~" | "++" | "+=" | "+" | "--" | "-="
| "-" | "?" | "||" | "|" | "|=" | "&&" | "&=" | "&" | "<<=" | "<<" | "<=" | "<" | "^="
| "-" | "??=" | "??" | '?' | "||" | "|" | "|=" | "&&" | "&=" | "&" | "<<=" | "<<" | "<=" | "<" | "^="
| "^" | "*=" | "*" | "/=" | "/" | "%=" | "%"
| <<unsignedShiftRightAssign>> | <<shiftRightAssign>> | <<unsignedShiftRight>> | <<shiftRight>>
| <<gtEq>> | ">" | "..." | "in" | '->' | "=>" | "new" | "is"
Expand All @@ -215,7 +216,7 @@ shiftOperator ::= unsignedShiftRightOperator | shiftRightOperator | shiftLeftOpe
shiftAssignOperator ::= unsignedShiftRightAssignOperator | shiftRightAssignOperator | shiftLeftAssignOperator

// TODO: Rename *.operation rules to *.operator.
assignOperation ::= '=' | '%=' | '*=' | '/=' | '+=' | '-=' | '&=' | '|=' | '^=' | shiftAssignOperator { extends=operator }
assignOperation ::= '=' | '%=' | '*=' | '/=' | '+=' | '-=' | '&=' | '|=' | '^=' | shiftAssignOperator | coalescingAssignOperator { extends=operator }
private gt ::= '>' !'>' // Cheaper than the predicates for all of the possible shift operators.
compareOperation ::= '==' | '!=' | '<=' | '<' | <<gtEq>> | gt { extends=operator }
bitOperation ::= '|' | '&' | '^' { extends=operator }
Expand All @@ -232,6 +233,7 @@ moduloOperator ::= '%' { extends=operator }
multiplicativeOperator ::= '*' | '/' { extends=operator }
prefixOperator ::= '-' | '!' | '~' { extends=operator }
coalescingOperator ::= '??' { extends=operator }
coalescingAssignOperator ::= '??=' { extends=operator }
questionOperator ::= <<ternary>> { extends=operator }
suffixOperator ::= '!' { extends=operator }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,16 @@ class OperatorTest {
toDyn = null ?? t;
toDyn = t ?? null;

toDyn ??= t;
toFloat ??= <error descr="Incompatible type: String should be Float" textAttributesKey="ERRORS_ATTRIBUTES">t</error>; // WRONG, trying to assign incorrect type

toDyn = null ?? null;

toDyn = s.toLowerCase().length ?? i;
toDyn = s?.toLowerCase()?.length ?? i;

toFloat = s?.toLowerCase()?.length ?? i;

toDyn = <error descr="Unable to apply operator ?? for types String and Int" textAttributesKey="ERRORS_ATTRIBUTES">s?.toLowerCase()?.charAt(i) ?? i</error>; // WRONG, can not unify types

toDyn = <error descr="Unable to apply operator ?? for types String and Bool" textAttributesKey="ERRORS_ATTRIBUTES">t ?? b</error>; // WRONG, can not unify types
Expand Down

0 comments on commit 2343506

Please sign in to comment.