Skip to content

Commit 7c73ba5

Browse files
committed
If a function has an error type, mangle it as '(Error) -> Error'.
This lets the mangling preserve the invariant that functions always structurally have function types. Error types don't show up in mangled names often anyway, but it can occur when you ask for the USR of a function with an invalid type.
1 parent c1b92db commit 7c73ba5

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,8 +1570,11 @@ CanType ASTMangler::getDeclTypeForMangling(
15701570
ArrayRef<Requirement> &requirements,
15711571
SmallVectorImpl<Requirement> &requirementsBuf) {
15721572
auto &C = decl->getASTContext();
1573-
if (!decl->hasInterfaceType())
1574-
return ErrorType::get(C)->getCanonicalType();
1573+
if (!decl->hasInterfaceType() || decl->getInterfaceType()->is<ErrorType>()) {
1574+
if (isa<AbstractFunctionDecl>(decl))
1575+
return CanFunctionType::get(C.TheErrorType, C.TheErrorType);
1576+
return C.TheErrorType;
1577+
}
15751578

15761579
auto type = decl->getInterfaceType()->getCanonicalType();
15771580

lib/Demangling/Demangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ NodePointer Demangler::demangleSpecialType() {
16351635
return createType(boxTy);
16361636
}
16371637
case 'e':
1638-
return createType(createNode(Node::Kind::ErrorType, StringRef()));
1638+
return createType(createNode(Node::Kind::ErrorType));
16391639
default:
16401640
return nullptr;
16411641
}

test/SourceKit/Indexing/index.swift.response

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@
11101110
{
11111111
key.kind: source.lang.swift.decl.function.method.instance,
11121112
key.name: "meth()",
1113-
key.usr: "s:5index4methXeF",
1113+
key.usr: "s:5index4methXeXeF",
11141114
key.line: 134,
11151115
key.column: 8
11161116
},

0 commit comments

Comments
 (0)