Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grammars/apex.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -3798,7 +3798,7 @@
<key>conditional-operator</key>
<dict>
<key>begin</key>
<string>(?&lt;!\?)\?(?!\?|\.|\[)</string>
<string>(?&lt;!\?)\?(?!\?|\.(?!\d)|\[)</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
Expand Down
2 changes: 1 addition & 1 deletion grammars/apex.tmLanguage.cson
Original file line number Diff line number Diff line change
Expand Up @@ -2242,7 +2242,7 @@ repository:
}
]
'conditional-operator':
begin: '(?<!\\?)\\?(?!\\?|\\.|\\[)'
begin: '(?<!\\?)\\?(?!\\?|\\.(?!\\d)|\\[)'
beginCaptures:
'0':
name: 'keyword.operator.conditional.question-mark.apex'
Expand Down
2 changes: 1 addition & 1 deletion grammars/soql.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -3780,7 +3780,7 @@
<key>conditional-operator</key>
<dict>
<key>begin</key>
<string>(?&lt;!\?)\?(?!\?|\.|\[)</string>
<string>(?&lt;!\?)\?(?!\?|\.(?!\d)|\[)</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
Expand Down
3 changes: 2 additions & 1 deletion src/apex.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,8 @@ repository:
# Only match ? if:
# 1. There isn't a preceding or trailing ? (null-coalescing operator)
# 2. There isn't a trailing . or [ (null-conditional operator)
begin: (?<!\?)\?(?!\?|\.|\[)
# 3. UNLESS the trailing . is followed by a digit (decimal literal like ?.34)
begin: (?<!\?)\?(?!\?|\.(?!\d)|\[)
beginCaptures:
'0': { name: keyword.operator.conditional.question-mark.apex }
end: ':'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* W-8095488: Ternary expression with decimals syntax highlighting
*
* When a ternary expression contains a decimal literal and spaces are excluded,
* the question mark may be incorrectly tokenized as a safe navigation operator
* instead of a ternary operator.
*/
public class TernaryWithDecimals_W8095488 {

// With spaces - should work correctly
public void ternaryWithSpaces() {
Boolean b = true;
Decimal d = b ? .34 : 0;
Decimal i = b?.123 : 0;
}

// Without spaces - potential tokenization issue
public void ternaryWithoutSpaces() {
Boolean b = true;
Decimal d = b?.34:0;
Decimal i = b?.123:0;
}

// Mixed scenarios
public void mixedScenarios() {
Boolean b = true;

// Space before question mark, no space after
Decimal d1 = b ?.34:0;

// No space before, space after
Decimal d2 = b? .34:0;

// Space after question mark, no space around colon
Decimal d3 = b? .34:0;

// All spaces
Decimal d4 = b ? .34 : 0;

// Integer values (for comparison)
Integer i1 = b?1:0;
Integer i2 = b ? 1 : 0;
}

// Safe navigation operator (for comparison)
public void safeNavigationOperator() {
String s = 'test';
Integer len = s?.length();

Account acc;
String name = acc?.Name;
}

// Complex expressions
public void complexExpressions() {
Boolean b = true;

// Ternary in switch
switch on (b) {
when true {
Decimal d = b?.34:0;
String s = 'SUCCESS';
}
}

// Nested ternary with decimals
Decimal nested = b ? (b?.5:.25) : .0;

// Ternary with decimal in variable declaration
Decimal inline = b?.99:0;
}

// Property access vs ternary
public void propertyVsTernary() {
Boolean b = true;

// These should be ternary operators, not safe navigation
Decimal d = b?.34:0;
Decimal i = b?.123:0;

// This is safe navigation
String type = this?.type;
}

String type = 'test';
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>58.0</apiVersion>
<status>Active</status>
</ApexClass>

Loading