Skip to content

[SourceKit] Format macro decl without crashing #76441

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 2 commits into from
Sep 18, 2024

Conversation

vincentisambart
Copy link
Contributor

Resolves #70002

Fix SourceKit crash occurring when formatting a macro with both an available attribute and a trailing closure.
SourceKit's formatting code was expecting trailing closures to only be present on expressions (Expr), but an available attribute on a macro makes it a declaration (Decl).

I don't have much knowledge of how SourceKit's formatting works so I wouldn't be surprised if this was incomplete.

@vincentisambart vincentisambart marked this pull request as ready for review September 13, 2024 05:50
@vincentisambart vincentisambart changed the title Format macro decl without crashing [SourceKit] Format macro decl without crashing Sep 13, 2024
@DougGregor
Copy link
Member

@swift-ci please smoke test

UIView()
}

// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s >%t.response
Copy link
Member

Choose a reason for hiding this comment

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

If you write the response into %t.response you should also check its contents.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the fix this test crashes, and indent-crashes.swift which seems to have a goal similar to this did write into %t.response without checking its content I thought it would be fine like this.
What do you think I should do?

  • Do not write into %t.response?
  • Write into %t.response and check the content? In that case should I change the test to be badly indented on purpose checking it properly gets into the expected shape?

Thanks

Copy link
Member

Choose a reason for hiding this comment

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

I would unindent UIView() and then check that the response correctly indents UIView() to one indentation level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ahoppen Thanks for the help! I just made the modifications you asked.
I also checked that running this test without my SourceKit changes still makes SourceKit crash and the test fail.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Great. Thank you for the fix. Looks good to me 👍🏽

@ahoppen
Copy link
Member

ahoppen commented Sep 18, 2024

@swift-ci Please smoke test

@ahoppen ahoppen enabled auto-merge September 18, 2024 14:52
@ahoppen ahoppen merged commit 6ab4f36 into swiftlang:main Sep 18, 2024
3 checks passed
@vincentisambart vincentisambart deleted the macro-decl-format branch September 18, 2024 22:29
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.

SourceKit crash for source.request.editor.formattext request
3 participants