Skip to content

[IDE] Fix assertion hit when a function call has no argument labels. #3907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/AST/SourceEntityWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,13 @@ bool SemaAnnotator::passCallArgNames(Expr *Fn, TupleExpr *TupleE) {

ArrayRef<Identifier> ArgNames = TupleE->getElementNames();
ArrayRef<SourceLoc> ArgLocs = TupleE->getElementNameLocs();
assert(ArgNames.size() == ArgLocs.size());
for (auto i : indices(ArgNames)) {
Identifier Name = ArgNames[i];
if (Name.empty())
continue;

SourceLoc Loc = ArgLocs[i];
if (Name.empty() || Loc.isInvalid())
if (Loc.isInvalid())
continue;

CharSourceRange Range{ Loc, Name.getLength() };
Expand Down
19 changes: 16 additions & 3 deletions test/IDE/annotation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ class C10 {
func meth(_ x: Int, withFloat: Float) {}
}

// 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)
// 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)
var c10 = C10(int: 0, andThis: 0)
// CHECK: <Var@[[@LINE-1]]:5>c10</Var>.<Func@[[@LINE-5]]:8>meth</Func>(0, <Func@[[@LINE-5]]:8>withFloat</Func>: 0)
// CHECK: <Var@[[@LINE-1]]:5>c10</Var>.<Func@[[@LINE-5]]:8>meth</Func>(0, <Func@[[@LINE-5]]:8#withFloat>withFloat</Func>: 0)
c10.meth(0, withFloat: 0)

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

func test8<T : Prot2>(_ x: T) {}
Expand Down Expand Up @@ -328,3 +328,16 @@ func test_defer() {
test_defer()
}
}

func test_arg_tuple1(_: Int, _: Int) {}
func test_arg_tuple2(p1: Int, _: Int) {}
func test_arg_tuple3(_: Int, p2: Int) {}
func test_arg_tuple4(p1: Int, p2: Int) {}
// CHECK: <Func@[[@LINE-4]]:6>test_arg_tuple1</Func>(0,0)
test_arg_tuple1(0,0)
// CHECK: <Func@[[@LINE-5]]:6>test_arg_tuple2</Func>(<Func@[[@LINE-5]]:6#p1>p1</Func>:0,0)
test_arg_tuple2(p1:0,0)
// CHECK: <Func@[[@LINE-6]]:6>test_arg_tuple3</Func>(0,<Func@[[@LINE-6]]:6#p2>p2</Func>:0)
test_arg_tuple3(0,p2:0)
// 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)
test_arg_tuple4(p1:0,p2:0)
14 changes: 13 additions & 1 deletion tools/swift-ide-test/swift-ide-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@ class AnnotationPrinter : public SourceEntityWalker {
ValueDecl *Dcl = nullptr;
TypeDecl *CtorTyRef = nullptr;
ModuleEntity Mod;
Identifier ArgName;
bool IsRef = true;

SemanticSourceEntity(CharSourceRange Range,
Expand All @@ -1128,6 +1129,14 @@ class AnnotationPrinter : public SourceEntityWalker {
ModuleEntity Mod)
: Range(Range),
Mod(Mod) {}

SemanticSourceEntity(CharSourceRange Range,
ValueDecl *Dcl,
Identifier argName)
: Range(Range),
Dcl(Dcl),
ArgName(argName),
IsRef(true) {}
};

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

bool visitCallArgName(Identifier Name, CharSourceRange Range,
ValueDecl *D) override {
annotateSourceEntity({ Range, D, nullptr, /*IsRef=*/true });
annotateSourceEntity({ Range, D, Name });
return true;
}

Expand Down Expand Up @@ -1228,6 +1237,9 @@ class AnnotationPrinter : public SourceEntityWalker {
OS << 'i';
OS << "Mod";
}
if (!Entity.ArgName.empty()) {
OS << "#" << Entity.ArgName.str();
}

OS << '>';
OS << Text;
Expand Down