Skip to content

Commit 5866d8a

Browse files
committed
Sema: Fix crash with invalid reference to macro
1 parent bf95643 commit 5866d8a

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

lib/Sema/TypeOfReference.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,13 +1652,6 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
16521652
return { openedType, openedType, memberTy, memberTy, Type() };
16531653
}
16541654

1655-
if (isa<AbstractFunctionDecl>(value) || isa<EnumElementDecl>(value)) {
1656-
if (value->getInterfaceType()->is<ErrorType>()) {
1657-
auto genericErrorTy = ErrorType::get(getASTContext());
1658-
return { genericErrorTy, genericErrorTy, genericErrorTy, genericErrorTy, Type() };
1659-
}
1660-
}
1661-
16621655
// Figure out the declaration context to use when opening this type.
16631656
DeclContext *innerDC = value->getInnermostDeclContext();
16641657
DeclContext *outerDC = value->getDeclContext();
@@ -1677,9 +1670,15 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
16771670
}
16781671

16791672
Type thrownErrorType;
1680-
if (isa<AbstractFunctionDecl>(value) || isa<EnumElementDecl>(value)) {
1673+
if (isa<AbstractFunctionDecl>(value) ||
1674+
isa<EnumElementDecl>(value) ||
1675+
isa<MacroDecl>(value)) {
1676+
auto interfaceType = value->getInterfaceType();
1677+
if (interfaceType->is<ErrorType>() || isa<MacroDecl>(value))
1678+
return { interfaceType, interfaceType, interfaceType, interfaceType, Type() };
1679+
16811680
// This is the easy case.
1682-
openedType = value->getInterfaceType()->castTo<AnyFunctionType>();
1681+
openedType = interfaceType->castTo<AnyFunctionType>();
16831682

16841683
if (auto *genericFn = openedType->getAs<GenericFunctionType>()) {
16851684
openedType = substGenericArgs(genericFn,

validation-test/compiler_crashers_2/2d564dafb1f91.swift renamed to validation-test/compiler_crashers_2_fixed/2d564dafb1f91.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"kind":"typecheck","signature":"swift::constraints::ConstraintSystem::getTypeOfMemberReference(swift::Type, swift::ValueDecl*, swift::DeclContext*, bool, swift::FunctionRefInfo, swift::constraints::ConstraintLocator*, llvm::SmallVectorImpl<std::__1::pair<swift::GenericTypeParamType*, swift::TypeVariableType*>>*, swift::constraints::PreparedOverloadBuilder*)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
class a {
44
macro b()
55
var c = b

0 commit comments

Comments
 (0)