Skip to content

Commit 76b9281

Browse files
committed
[Compile Time Constant Extraction] Handle expression-less default argument expressions
Resolves rdar://106006282
1 parent 86b8ca6 commit 76b9281

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/ConstExtract/ConstExtract.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,25 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
311311
return extractCompileTimeValue(underlyingToOpaque->getSubExpr());
312312
}
313313

314+
case ExprKind::DefaultArgument: {
315+
auto defaultArgExpr = cast<DefaultArgumentExpr>(expr);
316+
auto *decl = defaultArgExpr->getParamDecl();
317+
// If there is a default expr, we should have looked through to it
318+
assert(!decl->hasDefaultExpr());
319+
switch (decl->getDefaultArgumentKind()) {
320+
case DefaultArgumentKind::NilLiteral:
321+
return std::make_shared<RawLiteralValue>("nil");
322+
case DefaultArgumentKind::EmptyArray:
323+
return std::make_shared<ArrayValue>(
324+
std::vector<std::shared_ptr<CompileTimeValue>>());
325+
case DefaultArgumentKind::EmptyDictionary:
326+
return std::make_shared<DictionaryValue>(
327+
std::vector<std::shared_ptr<TupleValue>>());
328+
default:
329+
break;
330+
}
331+
} break;
332+
314333
default: {
315334
break;
316335
}

test/ConstExtraction/ExtractUnderlyingToOpaque.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
protocol MyProto {}
88
protocol Bird {}
9+
10+
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
911
struct UnderlyingToOpaquePropertyStruct : MyProto {
12+
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
1013
var warbler: some Bird {
1114
Warbler("blue")
1215
}

0 commit comments

Comments
 (0)