Skip to content

Commit 12c6118

Browse files
author
Nathan Hawes
committed
[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
1 parent 5bf394d commit 12c6118

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/AST/Decl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5109,6 +5109,14 @@ ParamDecl::getDefaultValueStringRepresentation(
51095109
DefaultValueAndIsVariadic.getPointer()->StringRepresentation;
51105110
if (!existing.empty())
51115111
return existing;
5112+
5113+
if (!getDefaultValue()) {
5114+
// TypeChecker::checkDefaultArguments() nulls out the default value
5115+
// if it fails to type check it. This only seems to happen with an
5116+
// invalid/incomplete parameter list that contains a parameter with an
5117+
// unresolved default value.
5118+
return "<<empty>>";
5119+
}
51125120
return extractInlinableText(getASTContext().SourceMgr, getDefaultValue(),
51135121
scratch);
51145122
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
enum LogLevel { case error }
2+
3+
func logAsync(level: LogLevel = undefined, messageProducer producer
4+
5+
// RUN: %sourcekitd-test -req=cursor -pos=3:44 %s -- %s | %FileCheck %s
6+
7+
// CHECK: source.lang.swift.decl.function.free (3:6-3:68)
8+
// CHECK: logAsync(level:messageProducer:)
9+
// CHECK: LogLevel</Type> = &lt;&lt;empty&gt;&gt

0 commit comments

Comments
 (0)