Skip to content

Commit c4941fb

Browse files
author
Nathan Hawes
authored
Merge pull request #21515 from nathawes/r46694149-cursor-info-crash-in-extractInlinableText
[sourcekitd][AST] Fix CursorInfo crash on method with unresolved default value
2 parents 8e38b67 + c3723fd commit c4941fb

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)