[sourcekitd][AST] Fix CursorInfo crash on method with unresolved default value

When printing its annotated decl, we would would assume the param's default
value is present if the default value kind was "Normal". The type checker
explicitly sets the default value to nullptr if it doesn't type check though, so
we were crashing for that case. Added the check.

Resolves rdar://problem/46694149
This commit is contained in:
Nathan Hawes
2018-12-21 15:50:25 -08:00
parent 83950babc9
commit c3723fd4d7
2 changed files with 17 additions and 0 deletions

View File

@@ -5101,6 +5101,14 @@ ParamDecl::getDefaultValueStringRepresentation(
auto existing = DefaultValueAndFlags.getPointer()->StringRepresentation;
if (!existing.empty())
return existing;
if (!getDefaultValue()) {
// TypeChecker::checkDefaultArguments() nulls out the default value
// if it fails to type check it. This only seems to happen with an
// invalid/incomplete parameter list that contains a parameter with an
// unresolved default value.
return "<<empty>>";
}
return extractInlinableText(getASTContext().SourceMgr, getDefaultValue(),
scratch);
}