Skip to content

Commit d67e89d

Browse files
committed
Sema: Fix handling of appliedPropertyWrappers in ConstraintSystem::replaySolution()
When we replay a solution, we must record changes in the trail, so fix the logic to do that. This fixes the first assertion failure with this test case. The test case also exposed a second issue. We synthesize a CustomAttr in applySolutionToClosurePropertyWrappers() with a type returned by simplifyType(). Eventually, CustomAttrNominalRequest::evaluate() looks at this type, and passes it to directReferencesForType(). Unfortunately, this entry point does not understand type aliases whose underlying type is a type parameter. However, directReferencesForType() is the wrong thing to use here, and we can just call getAnyNominal() instead. Fixes rdar://139237781.
1 parent 8f66bf1 commit d67e89d

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3812,7 +3812,7 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator,
38123812
directReferencesForTypeRepr(evaluator, ctx, typeRepr, dc,
38133813
defaultDirectlyReferencedTypeLookupOptions);
38143814
} else if (Type type = attr->getType()) {
3815-
decls = directReferencesForType(type);
3815+
return type->getAnyNominal();
38163816
}
38173817

38183818
// Dig out the nominal type declarations.

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6403,6 +6403,8 @@ ArgumentList *ExprRewriter::coerceCallArguments(
64036403
arg.setExpr(convertedArg);
64046404
newArgs.push_back(arg);
64056405
}
6406+
6407+
ASSERT(appliedWrapperIndex == appliedPropertyWrappers.size());
64066408
return ArgumentList::createTypeChecked(ctx, args, newArgs);
64076409
}
64086410

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5047,6 +5047,10 @@ void ConstraintSystem::removePropertyWrapper(Expr *anchor) {
50475047
auto &wrappers = found->second;
50485048
ASSERT(!wrappers.empty());
50495049
wrappers.pop_back();
5050+
if (wrappers.empty()) {
5051+
bool erased = appliedPropertyWrappers.erase(anchor);
5052+
ASSERT(erased);
5053+
}
50505054
}
50515055

50525056
ConstraintSystem::TypeMatchResult

lib/Sema/CSSolver.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,10 @@ void ConstraintSystem::replaySolution(const Solution &solution,
431431
for (const auto &appliedWrapper : solution.appliedPropertyWrappers) {
432432
auto found = appliedPropertyWrappers.find(appliedWrapper.first);
433433
if (found == appliedPropertyWrappers.end()) {
434-
appliedPropertyWrappers.insert(appliedWrapper);
434+
for (auto applied : appliedWrapper.second)
435+
applyPropertyWrapper(getAsExpr(appliedWrapper.first), applied);
435436
} else {
436-
auto &existing = found->second;
437-
ASSERT(existing.size() <= appliedWrapper.second.size());
438-
existing = appliedWrapper.second;
437+
ASSERT(found->second.size() == appliedWrapper.second.size());
439438
}
440439
}
441440

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx12
2+
3+
// REQUIRES: objc_interop
4+
// REQUIRES: OS=macosx
5+
6+
import SwiftUI
7+
8+
struct V: View {
9+
struct M: Identifiable {
10+
let id: String
11+
}
12+
13+
class C: ObservableObject {
14+
@Published var m: [M]
15+
16+
init() {
17+
self.m = []
18+
}
19+
}
20+
21+
@ObservedObject var c: C
22+
23+
var body: some View {
24+
Table($c.m) {
25+
TableColumn("") { $entry in
26+
Text("hi")
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)