Skip to content

Commit 81aa1fa

Browse files
committed
[SILGen] Handle same-type-to-concrete constraints in member initializers.
When emitting initialization code for stored properties that have default values within an initializer in an extension containing a same-type-to-concrete constraint, we can end up with conformances involving concrete types. Look for that conformance within the module of the initializer rather than asserting. Fixes rdar://problem/47723747.
1 parent 1e7fba7 commit 81aa1fa

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/SILGen/SILGenConstructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ void SILGenFunction::emitMemberInitializers(DeclContext *dc,
908908

909909
return Type(type);
910910
},
911-
MakeAbstractConformanceForGenericType());
911+
LookUpConformanceInModule(dc->getParentModule()));
912912
}
913913

914914
// Get the type of the initialization result, in terms

test/SILGen/initializers.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,3 +1129,21 @@ class SubVariadic : SuperVariadic { }
11291129
// CHECK: [[SUPER_INIT:%.*]] = function_ref @$s21failable_initializers13SuperVariadicC4intsACSid_tcfc
11301130
// CHECK: apply [[SUPER_INIT]]([[T1]], [[SELF_UPCAST]])
11311131
// CHECK-LABEL: } // end sil function
1132+
1133+
1134+
public struct MemberInits<Value : Equatable> {
1135+
private var box: MemberInitsHelper<Value>?
1136+
fileprivate var value: String = "default"
1137+
}
1138+
1139+
class MemberInitsHelper<T> { }
1140+
1141+
extension MemberInits {
1142+
// CHECK-LABEL: sil [ossa] @$s21failable_initializers11MemberInitsVyACySayqd__GGSayACyqd__GGcADRszSQRd__lufC : $@convention(method) <Value><T where Value == Array<T>, T : Equatable> (@owned Array<MemberInits<T>>, @thin MemberInits<Array<T>>.Type) -> @owned MemberInits<Array<T>> {
1143+
public init<T>(_ array: [MemberInits<T>]) where Value == [T] {
1144+
box = nil
1145+
1146+
// CHECK: [[INIT_FN:%.*]] = function_ref @$s21failable_initializers11MemberInitsV5value33_4497B2E9306011E5BAC13C07BEAC2557LLSSvpfi : $@convention(thin) <τ_0_0 where τ_0_0 : Equatable> () -> @owned String
1147+
// CHECK-NEXT: = apply [[INIT_FN]]<Array<T>>() : $@convention(thin) <τ_0_0 where τ_0_0 : Equatable> () -> @owned String
1148+
}
1149+
}

0 commit comments

Comments
 (0)