Skip to content

Commit a341b0f

Browse files
committed
[AST] Return whether type computation of EnumElementDecl succeeded
This is no change in functionality, but allows for easier bailing out when type-checking EnumElementDecls.
1 parent d1677bb commit a341b0f

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5270,7 +5270,9 @@ class EnumElementDecl : public ValueDecl {
52705270
static_cast<unsigned>(ElementRecursiveness::NotRecursive);
52715271
}
52725272

5273-
void computeType();
5273+
/// \returns false if there was an error during the computation rendering the
5274+
/// EnumElementDecl invalid, true otherwise.
5275+
bool computeType();
52745276

52755277
bool hasArgumentType() const { return !ArgumentType.getType().isNull(); }
52765278
Type getArgumentType() const { return ArgumentType.getType(); }

lib/AST/Decl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4309,7 +4309,7 @@ SourceRange EnumElementDecl::getSourceRange() const {
43094309
return {getStartLoc(), getNameLoc()};
43104310
}
43114311

4312-
void EnumElementDecl::computeType() {
4312+
bool EnumElementDecl::computeType() {
43134313
EnumDecl *ED = getParentEnum();
43144314

43154315
Type resultTy = ED->getDeclaredTypeInContext();
@@ -4326,6 +4326,7 @@ void EnumElementDecl::computeType() {
43264326
resultTy = FunctionType::get(argTy, resultTy);
43274327

43284328
setType(resultTy);
4329+
return true;
43294330
}
43304331

43314332
Type EnumElementDecl::getArgumentInterfaceType() const {

lib/Sema/TypeCheckDecl.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5543,11 +5543,14 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
55435543
EED->setRecursiveness(ElementRecursiveness::NotRecursive);
55445544
}
55455545

5546-
// Now that we have an argument type we can set the element's declared
5547-
// type.
5548-
if (!EED->hasType())
5549-
EED->computeType();
5550-
EED->setIsBeingTypeChecked(false);
5546+
{
5547+
defer { EED->setIsBeingTypeChecked(false); };
5548+
5549+
// Now that we have an argument type we can set the element's declared
5550+
// type.
5551+
if (!EED->hasType() && !EED->computeType())
5552+
return;
5553+
}
55515554

55525555
// Test for type parameters, as opposed to a generic decl context, in
55535556
// case the enclosing enum type was illegally declared inside of a generic

0 commit comments

Comments
 (0)