@@ -42,24 +42,38 @@ TypeRefinementContext::TypeRefinementContext(ASTContext &Ctx, IntroNode Node,
4242}
4343
4444TypeRefinementContext *
45- TypeRefinementContext::createRoot (SourceFile *SF,
46- const AvailabilityContext &Info) {
45+ TypeRefinementContext::createForSourceFile (SourceFile *SF,
46+ const AvailabilityContext &Info) {
4747 assert (SF);
4848
4949 ASTContext &Ctx = SF->getASTContext ();
5050
5151 SourceRange range;
5252 TypeRefinementContext *parentContext = nullptr ;
5353 AvailabilityContext availabilityContext = Info;
54- if (auto parentExpansion = SF->getMacroExpansion ()) {
54+ switch (SF->Kind ) {
55+ case SourceFileKind::MacroExpansion:
56+ case SourceFileKind::DefaultArgument: {
57+ // Look up the parent context in the enclosing file that this file's
58+ // root context should be nested under.
5559 if (auto parentTRC =
5660 SF->getEnclosingSourceFile ()->getTypeRefinementContext ()) {
5761 auto charRange = Ctx.SourceMgr .getRangeForBuffer (*SF->getBufferID ());
5862 range = SourceRange (charRange.getStart (), charRange.getEnd ());
59- parentContext = parentTRC->findMostRefinedSubContext (
60- parentExpansion.getStartLoc (), Ctx);
61- availabilityContext = parentContext->getAvailabilityInfo ();
63+ auto originalNode = SF->getNodeInEnclosingSourceFile ();
64+ parentContext =
65+ parentTRC->findMostRefinedSubContext (originalNode.getStartLoc (), Ctx);
66+ if (parentContext)
67+ availabilityContext = parentContext->getAvailabilityInfo ();
6268 }
69+ break ;
70+ }
71+ case SourceFileKind::Library:
72+ case SourceFileKind::Main:
73+ case SourceFileKind::Interface:
74+ break ;
75+ case SourceFileKind::SIL:
76+ llvm_unreachable (" unexpected SourceFileKind" );
6377 }
6478
6579 return new (Ctx)
0 commit comments