Skip to content

Commit 7cca6d6

Browse files
committed
[ASTDumper] Don't attempt to compute type USR for ModuleTypes.
`ModuleType`s show up in some rare places, like the left-hand-side of a `DotSyntaxBaseIgnoredExpr` for a module-qualified function call. ASTMangler does not support these because they're not real types.
1 parent d1227fb commit 7cca6d6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ std::string typeUSR(Type type) {
260260
if (!type)
261261
return "";
262262

263+
if (type->is<ModuleType>()) {
264+
// ASTMangler does not support "module types". This can appear, for
265+
// example, on the left-hand side of a `DotSyntaxBaseIgnoredExpr` for a
266+
// module-qualified free function call: `Swift.print()`.
267+
return "";
268+
}
263269
if (type->hasArchetype()) {
264270
type = type->mapTypeOutOfEnvironment();
265271
}
@@ -280,6 +286,13 @@ std::string declTypeUSR(const ValueDecl *D) {
280286
if (!D)
281287
return "";
282288

289+
if (isa<ModuleDecl>(D)) {
290+
// ASTMangler does not support "module types". This can appear, for
291+
// example, on the left-hand side of a `DotSyntaxBaseIgnoredExpr` for a
292+
// module-qualified free function call: `Swift.print()`.
293+
return "";
294+
}
295+
283296
std::string usr;
284297
llvm::raw_string_ostream os(usr);
285298
if (swift::ide::printDeclTypeUSR(D, os))

test/Frontend/ast-dump-json-no-crash.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,10 @@ dynamic func toBeReplaced(arg: Int) {}
484484

485485
@_dynamicReplacement(for: toBeReplaced(arg:))
486486
func toReplaceWith(arg: Int) {}
487+
488+
// Regression test: Swift 6.2 and earlier crashed trying to form the type USR
489+
// of the "module type" of a `DotSyntaxBaseIgnoredExpr` when calling a
490+
// module-qualified free function.
491+
func moduleTypeUSRRegressionTest() {
492+
Swift.print("")
493+
}

0 commit comments

Comments
 (0)