@@ -2842,7 +2842,19 @@ void FindLocalVal::visitBraceStmt(BraceStmt *S, bool isTopLevelCode) {
2842
2842
if (SM.isBeforeInBuffer (Loc, S->getStartLoc ()))
2843
2843
return ;
2844
2844
} else {
2845
- if (!isReferencePointInRange (S->getSourceRange ()))
2845
+ SourceRange CheckRange = S->getSourceRange ();
2846
+ if (S->isImplicit ()) {
2847
+ // If the brace statement is implicit, it doesn't have an explicit '}'
2848
+ // token. Thus, the last token in the brace stmt could be a string
2849
+ // literal token, which can *contain* its interpolation segments.
2850
+ // If one of these interpolation segments is the reference point, we'd
2851
+ // return false from `isReferencePointInRange` because the string
2852
+ // literal token's start location is before the interpolation token.
2853
+ // To fix this, adjust the range we are checking to range until the end of
2854
+ // the potential string interpolation token.
2855
+ CheckRange.End = Lexer::getLocForEndOfToken (SM, CheckRange.End );
2856
+ }
2857
+ if (!isReferencePointInRange (CheckRange))
2846
2858
return ;
2847
2859
}
2848
2860
@@ -2867,7 +2879,16 @@ void FindLocalVal::visitSwitchStmt(SwitchStmt *S) {
2867
2879
}
2868
2880
2869
2881
void FindLocalVal::visitCaseStmt (CaseStmt *S) {
2870
- if (!isReferencePointInRange (S->getSourceRange ()))
2882
+ // The last token in a case stmt can be a string literal token, which can
2883
+ // *contain* its interpolation segments. If one of these interpolation
2884
+ // segments is the reference point, we'd return false from
2885
+ // `isReferencePointInRange` because the string literal token's start location
2886
+ // is before the interpolation token. To fix this, adjust the range we are
2887
+ // checking to range until the end of the potential string interpolation
2888
+ // token.
2889
+ SourceRange CheckRange = {S->getStartLoc (),
2890
+ Lexer::getLocForEndOfToken (SM, S->getEndLoc ())};
2891
+ if (!isReferencePointInRange (CheckRange))
2871
2892
return ;
2872
2893
// Pattern names aren't visible in the patterns themselves,
2873
2894
// just in the body or in where guards.
0 commit comments