Skip to content

Commit 2d92894

Browse files
authored
Merge pull request swiftlang#27838 from slavapestov/caller-side-generic-arg-subst
Sema: Fix substitutions of generic caller-side default arguments
2 parents ace5d76 + 362488b commit 2d92894

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4980,8 +4980,8 @@ getCallerDefaultArg(ConstraintSystem &cs, DeclContext *dc,
49804980
}
49814981

49824982
// Convert the literal to the appropriate type.
4983-
auto defArgType = owner.getDecl()->getDeclContext()->mapTypeIntoContext(
4984-
param->getInterfaceType());
4983+
auto defArgType =
4984+
param->getInterfaceType().subst(owner.getSubstitutions());
49854985
auto resultTy =
49864986
tc.typeCheckParameterDefault(init, dc, defArgType,
49874987
/*isAutoClosure=*/param->isAutoClosure(),

test/SILGen/stored_property_default_arg.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,19 @@ func checkReferenceTuple() {
206206
// CHECK-NEXT: [[AA1:%.*]] = apply [[AA1_REF]]([[ELT0]], [[ELT1]], {{.*}}) : $@convention(method) (@owned Optional<Z>, @owned Optional<Z>, @thin AA.Type) -> @owned AA
207207
let ae = AA.init(ab:)()
208208
}
209+
210+
struct OptionalGeneric<T> {
211+
var t: T?
212+
var x: Int
213+
}
214+
215+
// CHECK-LABEL: sil hidden [ossa] @$s27stored_property_default_arg31checkDefaultInitGenericOptionalyyF : $@convention(thin) () -> () {
216+
func checkDefaultInitGenericOptional() {
217+
let og = OptionalGeneric<Int>(x: 0)
218+
219+
// CHECK: [[VALUE:%.*]] = enum $Optional<Int>, #Optional.none!enumelt
220+
// CHECK: [[NIL:%.*]] = alloc_stack $Optional<Int>
221+
// CHECK: store [[VALUE]] to [trivial] [[NIL]] : $*Optional<Int>
222+
// CHECK: [[FN:%.*]] = function_ref @$s27stored_property_default_arg15OptionalGenericV1t1xACyxGxSg_SitcfC : $@convention(method) <τ_0_0> (@in Optional<τ_0_0>, Int, @thin OptionalGeneric<τ_0_0>.Type) -> @out OptionalGeneric<τ_0_0>
223+
// CHECK: apply [[FN]]<Int>(%0, [[NIL]], {{%.*}}, %1)
224+
}

0 commit comments

Comments
 (0)