Skip to content

Commit 61421e8

Browse files
authored
Merge pull request #74423 from hamishknight/fully-typed
[CS] Fill in ErrorTypes for expressions that fail to type-check
2 parents 8582828 + 5ec4d1c commit 61421e8

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

lib/Sema/SyntacticElementTarget.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,15 @@ bool SyntacticElementTarget::contextualTypeIsOnlyAHint() const {
303303

304304
void SyntacticElementTarget::markInvalid() const {
305305
class InvalidationWalker : public ASTWalker {
306+
ASTContext &Ctx;
307+
308+
public:
309+
InvalidationWalker(ASTContext &ctx) : Ctx(ctx) {}
310+
306311
PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
307-
// TODO: We ought to fill in ErrorTypes for expressions here; ultimately
308-
// type-checking should always produce typed AST.
312+
if (!E->getType())
313+
E->setType(ErrorType::get(Ctx));
314+
309315
return Action::Continue(E);
310316
}
311317

@@ -321,7 +327,7 @@ void SyntacticElementTarget::markInvalid() const {
321327
return Action::VisitNodeIf(isa<PatternBindingDecl>(D));
322328
}
323329
};
324-
InvalidationWalker walker;
330+
InvalidationWalker walker(getDeclContext()->getASTContext());
325331
walk(walker);
326332
}
327333

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2706,7 +2706,7 @@ namespace {
27062706
PreWalkResult<Expr *> walkToExprPre(Expr *expr) override {
27072707
// Skip expressions that didn't make it to solution application
27082708
// because the constraint system diagnosed an error.
2709-
if (!expr->getType())
2709+
if (!expr->getType() || expr->getType()->hasError())
27102710
return Action::SkipNode(expr);
27112711

27122712
if (auto *openExistential = dyn_cast<OpenExistentialExpr>(expr)) {

lib/Sema/TypeCheckEffects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ class ApplyClassifier {
12831283
thrownValue = removeErasureToExistentialError(thrownValue);
12841284

12851285
Type thrownType = thrownValue->getType();
1286-
if (!thrownType)
1286+
if (!thrownType || thrownType->hasError())
12871287
return Classification::forInvalidCode();
12881288

12891289
// FIXME: Add a potential effect reason for a throw site.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %sourcekitd-test -req=cursor -pos=12:11 %s -- %s
2+
3+
private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
4+
5+
override func visitAny(_ node: Syntax) -> Syntax? {
6+
if var declSyntax = node.as(DeclSyntax.self),
7+
let attributedNode = node.asProtocol(WithAttributesSyntax.self),
8+
!attributedNode.attributes.isEmpty
9+
{
10+
for (attribute, spec) in attributesToRemove {
11+
if let index = self.expandedAttributes.firstIndex(where: { expandedAttribute in
12+
expandedAttribute.position == attribute.position
13+
}) {
14+
} else {
15+
}
16+
}
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)