Skip to content

Commit e3e9c64

Browse files
committed
SILGen: Fix incorrect assertion
Since 'decl' was already a StructDecl, 'decl->getDeclContext()' was giving us a non-generic module scope context. Fixes <https://bugs.swift.org/browse/SR-10075>.
1 parent 01f5855 commit e3e9c64

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/SILGen/SILGenConstructor.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
152152
if (!field->isStatic() && field->isLet() &&
153153
field->getParentInitializer()) {
154154
#ifndef NDEBUG
155-
auto fieldTy = decl->getDeclContext()->mapTypeIntoContext(
156-
field->getInterfaceType());
157-
assert(fieldTy->isEqual(field->getParentInitializer()->getType())
155+
assert(field->getType()->isEqual(field->getParentInitializer()->getType())
158156
&& "Checked by sema");
159157
#endif
160158

test/SILGen/default_constructor.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,15 @@ struct I {
121121
// CHECK: assign [[RESULT]] to [[X_ADDR]] : $*Int
122122
init<T>(_: T) {}
123123
}
124+
125+
// https://bugs.swift.org/browse/SR-10075
126+
func defaultValue<T>() -> T {
127+
fatalError()
128+
}
129+
130+
struct S<T> {
131+
let value1: T = defaultValue()
132+
let value2: Int
133+
134+
// CHECK-LABEL: sil hidden [ossa] @$s19default_constructor1SV6value2ACyxGSi_tcfC : $@convention(method) <T> (Int, @thin S<T>.Type) -> @out S<T>
135+
}

0 commit comments

Comments
 (0)