Skip to content

Commit 700be61

Browse files
committed
Sema: Fix crash with metatype construction -vs- dynamic Self
Fixes <rdar://problem/31297864>.
1 parent d1be8b0 commit 700be61

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2364,7 +2364,12 @@ ConstraintSystem::simplifyConstructionConstraint(
23642364
NameLookupOptions lookupOptions = defaultConstructorLookupOptions;
23652365
if (isa<AbstractFunctionDecl>(useDC))
23662366
lookupOptions |= NameLookupFlags::KnownPrivate;
2367-
auto ctors = TC.lookupConstructors(useDC, valueType, lookupOptions);
2367+
2368+
auto instanceType = valueType;
2369+
if (auto *selfType = instanceType->getAs<DynamicSelfType>())
2370+
instanceType = selfType->getSelfType();
2371+
2372+
auto ctors = TC.lookupConstructors(useDC, instanceType, lookupOptions);
23682373
if (!ctors)
23692374
return SolutionKind::Error;
23702375

test/decl/func/dynamic_self.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ class C1 {
9191

9292
return Self() // expected-error{{use of unresolved identifier 'Self'}} expected-note {{did you mean 'self'?}}
9393
}
94+
95+
// This used to crash because metatype construction went down a
96+
// different code path that didn't handle DynamicSelfType.
97+
class func badFactory() -> Self {
98+
return self(int: 0)
99+
// expected-error@-1 {{initializing from a metatype value must reference 'init' explicitly}}
100+
}
94101
}
95102

96103
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)