Skip to content

[CodeCompletion] Avoid crash for not recommended item without a decl #59490

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 1 commit into from
Jun 17, 2022

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jun 16, 2022

Generating diagnostics for "not recommended" items requires an associated declaration. However, cases like this:

  func test(fn: (Int) async -> Void) {
    fn(#^HERE^#)
  }

For the function call pattern item, there's no associated decl because the callee is an expression. Ideally it should emit a diagnostic, but for now, to avoid the crash, don't emit diagnostics unless the item has the associated decl.

rdar://95306033

@rintaro rintaro requested a review from bnbarham June 16, 2022 17:50
@rintaro
Copy link
Member Author

rintaro commented Jun 16, 2022

@swift-ci Please smoke test

@@ -30,3 +30,11 @@ func testActor(obj: MyActor) async {
// ACTOR-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended: receiveNonSendable({#arg: MyNonSendable#})[' async'][#Void#]; name=receiveNonSendable(arg:); diagnostics=warning:actor-isolated 'receiveNonSendable(arg:)' should only be referenced from inside the actor{{$}}
// ACTOR: End completions
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to test the contextual and context-free cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no case where ContextFreeNotRecReason != None && AssociatedDecl == nulptr at this point. Added an assertion to clarify, but still use dyn_cast_or_null just in case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, no crashes in release but we'll see with assertions enabled 👍

Generating diagnostics for "not recommended" items requires an
associated declaration. However, cases like this:

  func test(fn: (Int) async -> Void) {
    fn(#^HERE^#)
  }

For the function call pattern item, there's no associated decl because
the callee is an expression. Ideally it should emit a diagnostic, but
for now, to avoid the crash, don't emit diagnostics unless the item has
the associated decl.

rdar://95306033
@rintaro rintaro force-pushed the ide-completion-rdar95306033 branch from a675932 to e748ab4 Compare June 16, 2022 18:25
@rintaro
Copy link
Member Author

rintaro commented Jun 16, 2022

@swift-ci Please smoke test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants