Skip to content

Commit 73377fe

Browse files
committed
[NFC-ish] Fix some crashes from early Decl::dump()
Changes dump output used in one test; otherwise NFC.
1 parent 9b947f9 commit 73377fe

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,9 +1383,13 @@ namespace {
13831383
OS << "\")";
13841384
});
13851385
}
1386-
auto lifetimeString = getDumpString(VD->getLifetimeAnnotation());
1387-
if (!lifetimeString.empty())
1388-
printFlag(lifetimeString);
1386+
// In some cases, getLifetimeAnnotation() can fail before extension
1387+
// binding. hasResolvedImports() approximates an extension binding check.
1388+
if (VD->getModuleContext()->hasResolvedImports()) {
1389+
auto lifetimeString = getDumpString(VD->getLifetimeAnnotation());
1390+
if (!lifetimeString.empty())
1391+
printFlag(lifetimeString);
1392+
}
13891393
}
13901394

13911395
void printCommon(NominalTypeDecl *NTD, const char *Name, StringRef Label,
@@ -1905,8 +1909,13 @@ void swift::printContext(raw_ostream &os, DeclContext *dc) {
19051909
break;
19061910

19071911
case DeclContextKind::ExtensionDecl:
1908-
if (auto extendedNominal = cast<ExtensionDecl>(dc)->getExtendedNominal()) {
1912+
if (auto repr = cast<ExtensionDecl>(dc)->getExtendedTypeRepr()) {
1913+
repr->print(os);
1914+
} else if (cast<ExtensionDecl>(dc)->hasBeenBound()) {
1915+
auto extendedNominal = cast<ExtensionDecl>(dc)->getExtendedNominal();
19091916
printName(os, extendedNominal->getName());
1917+
} else {
1918+
os << "<unbound>";
19101919
}
19111920
os << " extension";
19121921
break;

test/type/parameterized_protocol.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-typecheck-verify-swift -disable-availability-checking
22

3-
// RUN: not %target-swift-frontend -typecheck %s -debug-generic-signatures -disable-availability-checking 2>&1 | %FileCheck %s
4-
3+
// RUN: not %target-swift-frontend -typecheck %s -debug-generic-signatures -disable-availability-checking >%t.output 2>&1
4+
// RUN: %FileCheck --input-file %t.output %s
55

66
/// Test some invalid syntax first
77

@@ -176,7 +176,7 @@ struct OpaqueTypes<E> {
176176
// CHECK: Generic signature: <Self where Self : Sequence, Self.[Sequence]Element == Int>
177177
extension Sequence<Int> {
178178

179-
// CHECK-LABEL: parameterized_protocol.(file).Sequence extension.doSomethingGeneric@
179+
// CHECK-LABEL: parameterized_protocol.(file).Sequence<Int> extension.doSomethingGeneric@
180180
// CHECK: Generic signature: <Self, E where Self : Sequence, Self.[Sequence]Element == Int>
181181
func doSomethingGeneric<E>(_: E) {}
182182
}

0 commit comments

Comments
 (0)