Skip to content

Commit 16e4294

Browse files
authored
Merge pull request #3907 from akyrtzi/tuple-arg-annotation-assertion-27611931
[IDE] Fix assertion hit when a function call has no argument labels.
2 parents 6b1210e + 5c46ed0 commit 16e4294

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

lib/AST/SourceEntityWalker.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,13 @@ bool SemaAnnotator::passCallArgNames(Expr *Fn, TupleExpr *TupleE) {
426426

427427
ArrayRef<Identifier> ArgNames = TupleE->getElementNames();
428428
ArrayRef<SourceLoc> ArgLocs = TupleE->getElementNameLocs();
429-
assert(ArgNames.size() == ArgLocs.size());
430429
for (auto i : indices(ArgNames)) {
431430
Identifier Name = ArgNames[i];
431+
if (Name.empty())
432+
continue;
433+
432434
SourceLoc Loc = ArgLocs[i];
433-
if (Name.empty() || Loc.isInvalid())
435+
if (Loc.isInvalid())
434436
continue;
435437

436438
CharSourceRange Range{ Loc, Name.getLength() };

test/IDE/annotation.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,13 @@ class C10 {
251251
func meth(_ x: Int, withFloat: Float) {}
252252
}
253253

254-
// CHECK: var <Var>c10</Var> = <Ctor@[[@LINE-4]]:3-Class@[[@LINE-5]]:7>C10</Ctor>(<Ctor@[[@LINE-4]]:3>int</Ctor>: 0, <Ctor@[[@LINE-4]]:3>andThis</Ctor>: 0)
254+
// CHECK: var <Var>c10</Var> = <Ctor@[[@LINE-4]]:3-Class@[[@LINE-5]]:7>C10</Ctor>(<Ctor@[[@LINE-4]]:3#int>int</Ctor>: 0, <Ctor@[[@LINE-4]]:3#andThis>andThis</Ctor>: 0)
255255
var c10 = C10(int: 0, andThis: 0)
256-
// CHECK: <Var@[[@LINE-1]]:5>c10</Var>.<Func@[[@LINE-5]]:8>meth</Func>(0, <Func@[[@LINE-5]]:8>withFloat</Func>: 0)
256+
// CHECK: <Var@[[@LINE-1]]:5>c10</Var>.<Func@[[@LINE-5]]:8>meth</Func>(0, <Func@[[@LINE-5]]:8#withFloat>withFloat</Func>: 0)
257257
c10.meth(0, withFloat: 0)
258258

259259
func test7(int x: Int, andThis y: Float) {}
260-
// CHECK: <Func@[[@LINE-1]]:6>test7</Func>(<Func@[[@LINE-1]]:6>int</Func>: 0, <Func@[[@LINE-1]]:6>andThis</Func>: 0)
260+
// CHECK: <Func@[[@LINE-1]]:6>test7</Func>(<Func@[[@LINE-1]]:6#int>int</Func>: 0, <Func@[[@LINE-1]]:6#andThis>andThis</Func>: 0)
261261
test7(int: 0, andThis: 0)
262262

263263
func test8<T : Prot2>(_ x: T) {}
@@ -328,3 +328,16 @@ func test_defer() {
328328
test_defer()
329329
}
330330
}
331+
332+
func test_arg_tuple1(_: Int, _: Int) {}
333+
func test_arg_tuple2(p1: Int, _: Int) {}
334+
func test_arg_tuple3(_: Int, p2: Int) {}
335+
func test_arg_tuple4(p1: Int, p2: Int) {}
336+
// CHECK: <Func@[[@LINE-4]]:6>test_arg_tuple1</Func>(0,0)
337+
test_arg_tuple1(0,0)
338+
// CHECK: <Func@[[@LINE-5]]:6>test_arg_tuple2</Func>(<Func@[[@LINE-5]]:6#p1>p1</Func>:0,0)
339+
test_arg_tuple2(p1:0,0)
340+
// CHECK: <Func@[[@LINE-6]]:6>test_arg_tuple3</Func>(0,<Func@[[@LINE-6]]:6#p2>p2</Func>:0)
341+
test_arg_tuple3(0,p2:0)
342+
// CHECK: <Func@[[@LINE-7]]:6>test_arg_tuple4</Func>(<Func@[[@LINE-7]]:6#p1>p1</Func>:0,<Func@[[@LINE-7]]:6#p2>p2</Func>:0)
343+
test_arg_tuple4(p1:0,p2:0)

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,7 @@ class AnnotationPrinter : public SourceEntityWalker {
11131113
ValueDecl *Dcl = nullptr;
11141114
TypeDecl *CtorTyRef = nullptr;
11151115
ModuleEntity Mod;
1116+
Identifier ArgName;
11161117
bool IsRef = true;
11171118

11181119
SemanticSourceEntity(CharSourceRange Range,
@@ -1128,6 +1129,14 @@ class AnnotationPrinter : public SourceEntityWalker {
11281129
ModuleEntity Mod)
11291130
: Range(Range),
11301131
Mod(Mod) {}
1132+
1133+
SemanticSourceEntity(CharSourceRange Range,
1134+
ValueDecl *Dcl,
1135+
Identifier argName)
1136+
: Range(Range),
1137+
Dcl(Dcl),
1138+
ArgName(argName),
1139+
IsRef(true) {}
11311140
};
11321141

11331142
bool walkToDeclPre(Decl *D, CharSourceRange Range) override {
@@ -1151,7 +1160,7 @@ class AnnotationPrinter : public SourceEntityWalker {
11511160

11521161
bool visitCallArgName(Identifier Name, CharSourceRange Range,
11531162
ValueDecl *D) override {
1154-
annotateSourceEntity({ Range, D, nullptr, /*IsRef=*/true });
1163+
annotateSourceEntity({ Range, D, Name });
11551164
return true;
11561165
}
11571166

@@ -1228,6 +1237,9 @@ class AnnotationPrinter : public SourceEntityWalker {
12281237
OS << 'i';
12291238
OS << "Mod";
12301239
}
1240+
if (!Entity.ArgName.empty()) {
1241+
OS << "#" << Entity.ArgName.str();
1242+
}
12311243

12321244
OS << '>';
12331245
OS << Text;

0 commit comments

Comments
 (0)