Skip to content

Commit c1db12a

Browse files
authored
Merge pull request #82239 from hamishknight/cod-cycle-6.2
[6.2] [Sema] Scale back CodingKeys hack in `TypeChecker::lookupUnqualifiedType`
2 parents 2bbc1c3 + 9ba1da9 commit c1db12a

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,6 @@ TypeChecker::lookupUnqualifiedType(DeclContext *dc, DeclNameRef name,
325325
NameLookupOptions options) {
326326
auto &ctx = dc->getASTContext();
327327

328-
// HACK: Synthesize CodingKeys if needed.
329-
synthesizeCodingKeysIfNeededForUnqualifiedLookup(ctx, dc, name);
330-
331328
auto ulOptions = convertToUnqualifiedLookupOptions(options) |
332329
UnqualifiedLookupFlags::TypeLookup;
333330
{
@@ -336,8 +333,15 @@ TypeChecker::lookupUnqualifiedType(DeclContext *dc, DeclNameRef name,
336333
name, dc, loc,
337334
ulOptions - UnqualifiedLookupFlags::AllowProtocolMembers);
338335

339-
auto lookup =
340-
evaluateOrDefault(ctx.evaluator, UnqualifiedLookupRequest{desc}, {});
336+
UnqualifiedLookupRequest req(desc);
337+
auto lookup = evaluateOrDefault(ctx.evaluator, req, {});
338+
339+
// HACK: Try synthesize CodingKeys if we got an empty result.
340+
if (lookup.allResults().empty() && name.isSimpleName(ctx.Id_CodingKeys)) {
341+
synthesizeCodingKeysIfNeededForUnqualifiedLookup(ctx, dc, name);
342+
lookup = evaluateOrDefault(ctx.evaluator, req, {});
343+
}
344+
341345
if (!lookup.allResults().empty())
342346
return lookup;
343347
}

test/Sema/rdar153096639.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// Make sure we don't run into a request cycle for the below use of 'CodingKeys'
4+
// in an `init(from:)` signature.
5+
6+
protocol P {
7+
associatedtype X
8+
}
9+
10+
struct S: Codable {
11+
var foo: String?
12+
13+
enum CodingKeys: CodingKey {
14+
case foo
15+
}
16+
17+
init<T: P>(from: T) where T.X == CodingKeys {}
18+
}

0 commit comments

Comments
 (0)