Skip to content

Commit 96fd946

Browse files
authored
Merge pull request #27839 from slavapestov/caller-side-generic-arg-subst-5.1
Sema: Fix substitutions of generic caller-side default arguments [5.1]
2 parents 471e4e9 + 80b2e73 commit 96fd946

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/Sema/CSApply.cpp

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

50955095
// Convert the literal to the appropriate type.
5096-
auto defArgType = owner.getDecl()->getDeclContext()->mapTypeIntoContext(
5097-
param->getInterfaceType());
5096+
auto defArgType =
5097+
param->getInterfaceType().subst(owner.getSubstitutions());
50985098
auto resultTy =
50995099
tc.typeCheckParameterDefault(init, dc, defArgType,
51005100
/*isAutoClosure=*/param->isAutoClosure(),

test/SILGen/stored_property_default_arg.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,20 @@ func checkReferenceTuple() {
207207
// CHECK-NEXT: [[AA1_REF:%.*]] = function_ref @$s27stored_property_default_arg2AAV2abAcA1ZCSg2ac_AG2adt_tcfC : $@convention(method) (@owned Optional<Z>, @owned Optional<Z>, @thin AA.Type) -> @owned AA
208208
// CHECK-NEXT: [[AA1:%.*]] = apply [[AA1_REF]]([[ELT0]], [[ELT1]], {{.*}}) : $@convention(method) (@owned Optional<Z>, @owned Optional<Z>, @thin AA.Type) -> @owned AA
209209
let ae = AA.init(ab:)()
210-
}
210+
}
211+
212+
struct OptionalGeneric<T> {
213+
var t: T?
214+
var x: Int
215+
}
216+
217+
// CHECK-LABEL: sil hidden [ossa] @$s27stored_property_default_arg31checkDefaultInitGenericOptionalyyF : $@convention(thin) () -> () {
218+
func checkDefaultInitGenericOptional() {
219+
let og = OptionalGeneric<Int>(x: 0)
220+
221+
// CHECK: [[VALUE:%.*]] = enum $Optional<Int>, #Optional.none!enumelt
222+
// CHECK: [[NIL:%.*]] = alloc_stack $Optional<Int>
223+
// CHECK: store [[VALUE]] to [trivial] [[NIL]] : $*Optional<Int>
224+
// 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>
225+
// CHECK: apply [[FN]]<Int>(%0, [[NIL]], {{%.*}}, %1)
226+
}

0 commit comments

Comments
 (0)