Skip to content

[CS] Fill in ErrorTypes for expressions that fail to type-check #74423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/Sema/SyntacticElementTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,15 @@ bool SyntacticElementTarget::contextualTypeIsOnlyAHint() const {

void SyntacticElementTarget::markInvalid() const {
class InvalidationWalker : public ASTWalker {
ASTContext &Ctx;

public:
InvalidationWalker(ASTContext &ctx) : Ctx(ctx) {}

PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
// TODO: We ought to fill in ErrorTypes for expressions here; ultimately
// type-checking should always produce typed AST.
if (!E->getType())
E->setType(ErrorType::get(Ctx));

return Action::Continue(E);
}

Expand All @@ -321,7 +327,7 @@ void SyntacticElementTarget::markInvalid() const {
return Action::VisitNodeIf(isa<PatternBindingDecl>(D));
}
};
InvalidationWalker walker;
InvalidationWalker walker(getDeclContext()->getASTContext());
walk(walker);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2706,7 +2706,7 @@ namespace {
PreWalkResult<Expr *> walkToExprPre(Expr *expr) override {
// Skip expressions that didn't make it to solution application
// because the constraint system diagnosed an error.
if (!expr->getType())
if (!expr->getType() || expr->getType()->hasError())
return Action::SkipNode(expr);

if (auto *openExistential = dyn_cast<OpenExistentialExpr>(expr)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ class ApplyClassifier {
thrownValue = removeErasureToExistentialError(thrownValue);

Type thrownType = thrownValue->getType();
if (!thrownType)
if (!thrownType || thrownType->hasError())
return Classification::forInvalidCode();

// FIXME: Add a potential effect reason for a throw site.
Expand Down
19 changes: 19 additions & 0 deletions test/SourceKit/CursorInfo/rdar129417672.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %sourcekitd-test -req=cursor -pos=12:11 %s -- %s

private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {

override func visitAny(_ node: Syntax) -> Syntax? {
if var declSyntax = node.as(DeclSyntax.self),
let attributedNode = node.asProtocol(WithAttributesSyntax.self),
!attributedNode.attributes.isEmpty
{
for (attribute, spec) in attributesToRemove {
if let index = self.expandedAttributes.firstIndex(where: { expandedAttribute in
expandedAttribute.position == attribute.position
}) {
} else {
}
}
}
}
}