Skip to content

Conversation

@stmontgomery
Copy link
Contributor

This fixes an issue where certain trivia, such as a newline (\n) placed in between the func keyword and a function's name on a function with the @Test attribute causes an error in the macro expansion code. For example:

@Test func
nameOnSecondLine() { ... }

Modifications:

Trim trivia from function name in macro expansion code.

Result:

These examples now build without errors.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

Resolves rdar://130797660

@stmontgomery stmontgomery added the bug 🪲 Something isn't working label Jul 2, 2024
@stmontgomery stmontgomery self-assigned this Jul 2, 2024
@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@JetForMe
Copy link

Wild. This literally wasn't working when I wrote #561 a day or two ago, but now it does. It seems both CLI Swift and Xcode will implicitly include a version of Swift Testing. Adding the explicit dependency to Package.swift on branch main picks up this commit and tests behave as expected. Sorry for the noise!

@JetForMe
Copy link

JetForMe commented Jul 22, 2024

@stmontgomery May I ask: It seems like this is a shortcoming of swift-syntax, right? In that it produces functionDecl.name with surrounding whitespace? Should I open an issue there?

@bnbarham
Copy link
Contributor

@stmontgomery May I ask: It seems like this is a shortcoming of swift-syntax, right? In that it produces functionDecl.name with surrounding whitespace? Should I open an issue there?

This is intentional on the swift-syntax side - the tree produced by swift-syntax is intended to provide source fidelity, ie. the tree is always a faithful recreation of the source code it was given as input. name here is actually a TokenSyntax which includes trivia around it (both whitespace and eg. comments). It was being used directly to produce a call, which thus also included its trivia. Using .trimmed is the correct change.

@JetForMe
Copy link

Probably a discussion to have over there, but how do they decide that the surrounding whitespace belongs to the function name and not some other token? Seems like it would be better to have tokens like <func>``<whitespace>``<func name>, etc. Because I'd argue that intuitively, the whitespace is definitely not part of the function name.

@grynspan
Copy link
Contributor

Let's continue this discussion in the forums.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🪲 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants