Skip to content

Commit f302c20

Browse files
committed
[AST] When cloning a parameter list, always set the default argument kind
to none when default arguments are not inherited.
1 parent 85891c9 commit f302c20

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/AST/Parameter.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ ParameterList *ParameterList::clone(const ASTContext &C,
6060

6161
// Remap the ParamDecls inside of the ParameterList.
6262
for (auto &decl : params) {
63-
bool hadDefaultArgument =
64-
decl->getDefaultArgumentKind() == DefaultArgumentKind::Normal;
63+
auto defaultArgKind = decl->getDefaultArgumentKind();
6564

6665
decl = ParamDecl::cloneWithoutType(C, decl);
6766
if (options & Implicit)
@@ -74,11 +73,18 @@ ParameterList *ParameterList::clone(const ASTContext &C,
7473

7574
// If we're inheriting a default argument, mark it as such.
7675
// FIXME: Figure out how to clone default arguments as well.
77-
if (hadDefaultArgument) {
78-
if (options & Inherited)
76+
if (options & Inherited) {
77+
switch (defaultArgKind) {
78+
case DefaultArgumentKind::Normal:
79+
case DefaultArgumentKind::StoredProperty:
7980
decl->setDefaultArgumentKind(DefaultArgumentKind::Inherited);
80-
else
81-
decl->setDefaultArgumentKind(DefaultArgumentKind::None);
81+
break;
82+
83+
default:
84+
break;
85+
}
86+
} else {
87+
decl->setDefaultArgumentKind(DefaultArgumentKind::None);
8288
}
8389
}
8490

test/SILGen/default_arguments.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,23 @@ func testCallableWithDefault(_ x: CallableWithDefault) {
434434
x(y: 5)
435435
}
436436

437+
enum E {
438+
// CHECK-LABEL: sil hidden [ossa] @$s17default_arguments1EO6ResultV4name9platformsAESS_SaySiGtcfcfA0_ : $@convention(thin) () -> @owned Array<Int>
439+
struct Result {
440+
var name: String
441+
var platforms: [Int] = []
442+
}
443+
444+
// CHECK-LABEL: sil hidden [ossa] @$s17default_arguments1EO4testyyFZ : $@convention(method) (@thin E.Type) -> ()
445+
static func test() {
446+
// CHECK: function_ref @$s17default_arguments1EO6ResultV4name9platformsAESS_SaySiGtcfcfA0_ : $@convention(thin) () -> @owned Array<Int>
447+
// CHECK: function_ref @$s17default_arguments1EO4testyyFZAC6ResultVSS_SaySiGtcfu_ : $@convention(thin) (@guaranteed String, @guaranteed Array<Int>) -> @owned E.Result
448+
449+
// CHECK-LABEL: sil private [ossa] @$s17default_arguments1EO4testyyFZAC6ResultVSS_SaySiGtcfu_ : $@convention(thin) (@guaranteed String, @guaranteed Array<Int>) -> @owned E.Result
450+
var result = Self.Result(name: "")
451+
}
452+
}
453+
437454
// FIXME: Arguably we shouldn't allow calling a constructor like this, as
438455
// we usually require the user write an explicit '.init'.
439456
struct WeirdUMEInitCase {

0 commit comments

Comments
 (0)