mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[cursor-info] Fix crash due to invalid base type in the PrintOptions passed to the AST printer
Resolves rdar://problem/30248264 Also added test cases for rdar://problem/30292429 (already fixed)
This commit is contained in:
14
test/SourceKit/CursorInfo/rdar_30248264.swift
Normal file
14
test/SourceKit/CursorInfo/rdar_30248264.swift
Normal file
@@ -0,0 +1,14 @@
|
||||
// Checks that we don't crash.
|
||||
// RUN: %sourcekitd-test -req=cursor -pos=9:25 %s -- %s | %FileCheck %s
|
||||
// RUN: %sourcekitd-test -req=cursor -pos=11:13 %s -- %s | %FileCheck -check-prefix=CHECK2 %s
|
||||
|
||||
class A {
|
||||
static prefix func +(_:A) {}
|
||||
|
||||
func method() {
|
||||
let _ = "" /*here:*/== ""
|
||||
// CHECK: source.lang.swift.ref.function.operator.infix
|
||||
/*here*/+A()
|
||||
// CHECK2: source.lang.swift.ref.function.operator.prefix
|
||||
}
|
||||
}
|
||||
16
test/SourceKit/CursorInfo/rdar_30292429.swift
Normal file
16
test/SourceKit/CursorInfo/rdar_30292429.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
// Checks that we don't crash.
|
||||
// RUN: %sourcekitd-test -req=cursor -pos=10:17 %s -- %s | %FileCheck -check-prefix=CHECK %s
|
||||
// RUN: %sourcekitd-test -req=cursor -pos=13:22 %s -- %s | %FileCheck -check-prefix=CHECK2 %s
|
||||
|
||||
class A {
|
||||
var field: Bool = true
|
||||
var items: [Int] = []
|
||||
|
||||
func method() {
|
||||
if /*here:*/field {}
|
||||
// CHECK: source.lang.swift.ref.var.instance
|
||||
|
||||
for _ in /*here*/items {}
|
||||
// CHECK2: source.lang.swift.ref.var.instance
|
||||
}
|
||||
}
|
||||
@@ -455,7 +455,7 @@ template <typename FnTy>
|
||||
void walkRelatedDecls(const ValueDecl *VD, const FnTy &Fn) {
|
||||
llvm::SmallDenseMap<DeclName, unsigned, 16> NamesSeen;
|
||||
++NamesSeen[VD->getFullName()];
|
||||
SmallVector<ValueDecl *, 8> RelatedDecls;
|
||||
SmallVector<UnqualifiedLookupResult, 8> RelatedDecls;
|
||||
|
||||
if (isa<ParamDecl>(VD))
|
||||
return; // Parameters don't have interesting related declarations.
|
||||
@@ -473,13 +473,16 @@ void walkRelatedDecls(const ValueDecl *VD, const FnTy &Fn) {
|
||||
|
||||
if (RelatedVD != VD) {
|
||||
++NamesSeen[RelatedVD->getFullName()];
|
||||
RelatedDecls.push_back(RelatedVD);
|
||||
RelatedDecls.push_back(result);
|
||||
}
|
||||
}
|
||||
|
||||
// Now provide the results along with whether the name is duplicate or not.
|
||||
for (auto RelatedVD : RelatedDecls) {
|
||||
Fn(RelatedVD, NamesSeen[RelatedVD->getFullName()] > 1);
|
||||
ValueDecl *OriginalBase = VD->getDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
|
||||
for (auto Related : RelatedDecls) {
|
||||
ValueDecl *RelatedVD = Related.getValueDecl();
|
||||
bool SameBase = Related.getBaseDecl() && Related.getBaseDecl() == OriginalBase;
|
||||
Fn(RelatedVD, SameBase, NamesSeen[RelatedVD->getFullName()] > 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -741,7 +744,7 @@ static bool passCursorInfoForDecl(const ValueDecl *VD,
|
||||
});
|
||||
|
||||
DelayedStringRetriever RelDeclsStream(SS);
|
||||
walkRelatedDecls(VD, [&](const ValueDecl *RelatedDecl, bool DuplicateName) {
|
||||
walkRelatedDecls(VD, [&](const ValueDecl *RelatedDecl, bool UseOriginalBase, bool DuplicateName) {
|
||||
RelDeclsStream.startPiece();
|
||||
{
|
||||
RelDeclsStream<<"<RelatedName usr=\"";
|
||||
@@ -755,7 +758,7 @@ static bool passCursorInfoForDecl(const ValueDecl *VD,
|
||||
PO.SkipIntroducerKeywords = true;
|
||||
PO.ArgAndParamPrinting = PrintOptions::ArgAndParamPrintingMode::ArgumentOnly;
|
||||
XMLEscapingPrinter Printer(RelDeclsStream);
|
||||
if (BaseType) {
|
||||
if (UseOriginalBase && BaseType) {
|
||||
PO.setBaseType(BaseType);
|
||||
PO.PrintAsMember = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user