[Compile Time Constant Extraction] Handle expression-less default argument expressions

Resolves rdar://106006282
This commit is contained in:
Artem Chikin
2023-03-01 15:00:10 -08:00
parent 86b8ca6f91
commit 76b9281fac
2 changed files with 22 additions and 0 deletions

View File

@@ -311,6 +311,25 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
return extractCompileTimeValue(underlyingToOpaque->getSubExpr());
}
case ExprKind::DefaultArgument: {
auto defaultArgExpr = cast<DefaultArgumentExpr>(expr);
auto *decl = defaultArgExpr->getParamDecl();
// If there is a default expr, we should have looked through to it
assert(!decl->hasDefaultExpr());
switch (decl->getDefaultArgumentKind()) {
case DefaultArgumentKind::NilLiteral:
return std::make_shared<RawLiteralValue>("nil");
case DefaultArgumentKind::EmptyArray:
return std::make_shared<ArrayValue>(
std::vector<std::shared_ptr<CompileTimeValue>>());
case DefaultArgumentKind::EmptyDictionary:
return std::make_shared<DictionaryValue>(
std::vector<std::shared_ptr<TupleValue>>());
default:
break;
}
} break;
default: {
break;
}

View File

@@ -6,7 +6,10 @@
protocol MyProto {}
protocol Bird {}
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
struct UnderlyingToOpaquePropertyStruct : MyProto {
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
var warbler: some Bird {
Warbler("blue")
}