Skip to content

Commit 1a844ef

Browse files
committed
Ignore error types in VariableTypeCollector
Also add a test to verify that error types get ignored (as intended).
1 parent 7a73c99 commit 1a844ef

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Diff for: lib/IDE/IDETypeChecking.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -796,15 +796,20 @@ class VariableTypeCollector : public SourceEntityWalker {
796796
llvm::raw_svector_ostream OS(Buffer);
797797
PrintOptions Options;
798798
Options.SynthesizeSugarOnTypes = true;
799-
VD->getType()->print(OS, Options);
799+
auto Ty = VD->getType();
800+
// Skip this declaration if the type is an error type.
801+
if (Ty->is<ErrorType>()) {
802+
return false;
803+
}
804+
Ty->print(OS, Options);
800805
}
801806
// Transfer the type to `OS` if needed and get the offsets of this string
802807
// in `OS`.
803-
auto Ty = getTypeOffsets(Buffer.str());
808+
auto TyOffsets = getTypeOffsets(Buffer.str());
804809
bool HasExplicitType =
805810
VD->getTypeReprOrParentPatternTypeRepr() != nullptr;
806811
// Add the type information to the result list.
807-
Results.emplace_back(VarOffset, VarLength, HasExplicitType, Ty.first);
812+
Results.emplace_back(VarOffset, VarLength, HasExplicitType, TyOffsets.first);
808813
}
809814
return true;
810815
}

Diff for: test/SourceKit/VariableType/error.swift

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let x = "an error type" + 3
2+
let y = "not an error type"
3+
4+
// RUN: %sourcekitd-test -req=collect-var-type %s -- %s | %FileCheck %s
5+
// CHECK-NOT: (1:5, 1:6)
6+
// CHECK: (2:5, 2:6): String (explicit type: 0)

0 commit comments

Comments
 (0)