Skip to content

Commit 7ae4cc6

Browse files
committed
Sema: We can end up in deriveConformanceForInvertible() with a NominalTypeDecl from a SynthesizedFileUnit
1 parent 4f2ad8f commit 7ae4cc6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/Sema/TypeCheckInvertible.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ ProtocolConformance *deriveConformanceForInvertible(Evaluator &evaluator,
381381
if (!ip)
382382
llvm_unreachable("not an invertible protocol");
383383

384+
auto file = cast<FileUnit>(nominal->getModuleScopeContext());
385+
384386
// Generates a conformance for the nominal to the protocol.
385387
// The conformanceDC specifies THE decl context to use for the conformance.
386388
auto generateConformance =
@@ -430,7 +432,6 @@ ProtocolConformance *deriveConformanceForInvertible(Evaluator &evaluator,
430432
nominal->addExtension(ext);
431433

432434
// Make it accessible to getTopLevelDecls() so it gets type-checked.
433-
auto file = cast<FileUnit>(nominal->getModuleScopeContext());
434435
file->getOrCreateSynthesizedFile().addTopLevelDecl(ext);
435436

436437
// Then create the conformance using the extension as the conformance's
@@ -469,8 +470,10 @@ ProtocolConformance *deriveConformanceForInvertible(Evaluator &evaluator,
469470
//
470471
// I'm currently unsure what happens when rebuilding a module from its
471472
// interface, so this might not be unreachable code just yet.
472-
if (SWIFT_ENABLE_EXPERIMENTAL_NONCOPYABLE_GENERICS)
473+
if (SWIFT_ENABLE_EXPERIMENTAL_NONCOPYABLE_GENERICS &&
474+
file->getKind() != FileUnitKind::Synthesized) {
473475
llvm_unreachable("when can this actually happen??");
476+
}
474477

475478
// If there's no inverse, we infer a positive IP conformance.
476479
return generateConformance(nominal);

0 commit comments

Comments
 (0)