Skip to content

Commit c3723fd

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 83950ba commit c3723fd

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
@@ -5101,6 +5101,14 @@ ParamDecl::getDefaultValueStringRepresentation(
51015101
auto existing = DefaultValueAndFlags.getPointer()->StringRepresentation;
51025102
if (!existing.empty())
51035103
return existing;
5104+
5105+
if (!getDefaultValue()) {
5106+
// TypeChecker::checkDefaultArguments() nulls out the default value
5107+
// if it fails to type check it. This only seems to happen with an
5108+
// invalid/incomplete parameter list that contains a parameter with an
5109+
// unresolved default value.
5110+
return "<<empty>>";
5111+
}
51045112
return extractInlinableText(getASTContext().SourceMgr, getDefaultValue(),
51055113
scratch);
51065114
}
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)