Skip to content

Sema: Fix substitutions of generic caller-side default arguments [5.1] #27839

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
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
4 changes: 2 additions & 2 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5093,8 +5093,8 @@ getCallerDefaultArg(ConstraintSystem &cs, DeclContext *dc,
}

// Convert the literal to the appropriate type.
auto defArgType = owner.getDecl()->getDeclContext()->mapTypeIntoContext(
param->getInterfaceType());
auto defArgType =
param->getInterfaceType().subst(owner.getSubstitutions());
auto resultTy =
tc.typeCheckParameterDefault(init, dc, defArgType,
/*isAutoClosure=*/param->isAutoClosure(),
Expand Down
18 changes: 17 additions & 1 deletion test/SILGen/stored_property_default_arg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,20 @@ func checkReferenceTuple() {
// 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
// CHECK-NEXT: [[AA1:%.*]] = apply [[AA1_REF]]([[ELT0]], [[ELT1]], {{.*}}) : $@convention(method) (@owned Optional<Z>, @owned Optional<Z>, @thin AA.Type) -> @owned AA
let ae = AA.init(ab:)()
}
}

struct OptionalGeneric<T> {
var t: T?
var x: Int
}

// CHECK-LABEL: sil hidden [ossa] @$s27stored_property_default_arg31checkDefaultInitGenericOptionalyyF : $@convention(thin) () -> () {
func checkDefaultInitGenericOptional() {
let og = OptionalGeneric<Int>(x: 0)

// CHECK: [[VALUE:%.*]] = enum $Optional<Int>, #Optional.none!enumelt
// CHECK: [[NIL:%.*]] = alloc_stack $Optional<Int>
// CHECK: store [[VALUE]] to [trivial] [[NIL]] : $*Optional<Int>
// 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>
// CHECK: apply [[FN]]<Int>(%0, [[NIL]], {{%.*}}, %1)
}