Skip to content

Commit 9151c70

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

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-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
}

0 commit comments

Comments
 (0)