Skip to content

[SILGen] Don't crash when calling a generic init with default args. #7169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3668,11 +3668,13 @@ void ArgEmitter::emitShuffle(Expr *inner,
// Emit the inner expression.
SmallVector<ManagedValue, 8> innerArgs;
SmallVector<InOutArgument, 2> innerInOutArgs;
ArgEmitter(SGF, Rep, ClaimedParamsRef(innerParams), innerArgs, innerInOutArgs,
/*foreign error*/ None, /*foreign self*/ ImportAsMemberStatus(),
(innerSpecialDests ? ArgSpecialDestArray(*innerSpecialDests)
: Optional<ArgSpecialDestArray>()))
.emitTopLevel(ArgumentSource(inner), innerOrigParamType);
if (!innerParams.empty()) {
ArgEmitter(SGF, Rep, ClaimedParamsRef(innerParams), innerArgs, innerInOutArgs,
/*foreign error*/ None, /*foreign self*/ ImportAsMemberStatus(),
(innerSpecialDests ? ArgSpecialDestArray(*innerSpecialDests)
: Optional<ArgSpecialDestArray>()))
.emitTopLevel(ArgumentSource(inner), innerOrigParamType);
}

// Make a second pass to split the inner arguments correctly.
{
Expand Down
18 changes: 18 additions & 0 deletions test/SILGen/default_arguments_generic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,21 @@ func bar() {
// CHECK: apply [[ZANG_DFLT_1]]<Int, Double>
Zim<Int>.zang(Double.self, 22)
}

protocol Initializable {
init()
}
struct Generic<T: Initializable> {
init(_ value: T = T()) {}
}
struct InitializableImpl: Initializable {
init() {}
}
// CHECK-LABEL: sil hidden @_T025default_arguments_generic17testInitializableyyF
func testInitializable() {
// The ".init" is required to trigger the crash that used to happen.
_ = Generic<InitializableImpl>.init()
// CHECK: [[INIT:%.+]] = function_ref @_T025default_arguments_generic7GenericVACyxGxcfC
// CHECK: function_ref @_T025default_arguments_generic7GenericVACyxGxcfcfA_ : $@convention(thin) <τ_0_0 where τ_0_0 : Initializable> () -> @out τ_0_0
// CHECK: apply [[INIT]]<InitializableImpl>({{%.+}}, {{%.+}}) : $@convention(method) <τ_0_0 where τ_0_0 : Initializable> (@in τ_0_0, @thin Generic<τ_0_0>.Type) -> Generic<τ_0_0>
} // CHECK: end sil function '_T025default_arguments_generic17testInitializableyyF'