File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,10 @@ class Identifier {
122
122
is (" >" ) || is (" <=" ) || is (" >=" );
123
123
}
124
124
125
+ bool isNilCoalescingOperator () const {
126
+ return is (" ??" );
127
+ }
128
+
125
129
// / isOperatorStartCodePoint - Return true if the specified code point is a
126
130
// / valid start of an operator.
127
131
static bool isOperatorStartCodePoint (uint32_t C) {
Original file line number Diff line number Diff line change @@ -212,7 +212,15 @@ namespace {
212
212
return { false , expr };
213
213
}
214
214
215
- if (isa<BinaryExpr>(expr)) {
215
+ if (auto *binaryExpr = dyn_cast<BinaryExpr>(expr)) {
216
+ if (auto *overload = dyn_cast<OverloadedDeclRefExpr>(binaryExpr->getFn ())) {
217
+ // Don't walk into nil coalescing operators. Attempting to favor
218
+ // based on operand types is wrong for this operator.
219
+ auto identifier = overload->getDecls ().front ()->getBaseIdentifier ();
220
+ if (identifier.isNilCoalescingOperator ())
221
+ return { false , expr };
222
+ }
223
+
216
224
LTI.binaryExprs .push_back (dyn_cast<BinaryExpr>(expr));
217
225
}
218
226
@@ -367,7 +375,7 @@ namespace {
367
375
368
376
return true ;
369
377
}
370
-
378
+
371
379
return false ;
372
380
}
373
381
Original file line number Diff line number Diff line change
1
+ // RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
2
+
3
+ struct B {
4
+ static var _none : B { B ( ) }
5
+ }
6
+
7
+ struct A {
8
+ init ( _ other: B ) { }
9
+ // CHECK: constructor_decl{{.*}}interface type='(A.Type) -> (B?) -> A'
10
+ init ( _ other: B ? ) {
11
+ // CHECK: dot_syntax_call_expr type='(B) -> A'
12
+ self . init ( other ?? . _none)
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments