Skip to content
Closed
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
2 changes: 1 addition & 1 deletion lib/Macros/Sources/ObservationMacros/ObservableMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ extension VariableDeclSyntax {
leadingTrivia: leadingTrivia,
attributes: newAttributes,
modifiers: modifiers.privatePrefixed(prefix, in: context),
bindingSpecifier: TokenSyntax(bindingSpecifier.tokenKind, leadingTrivia: .space, trailingTrivia: .space, presence: .present),
bindingSpecifier: TokenSyntax(bindingSpecifier.tokenKind, leadingTrivia: .newline, trailingTrivia: .space, presence: .present),
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we'd actually want a newline on the modifiers if there are any, then a space on the var/let if there is, and a newline otherwise. Also need trivia on the added attribute, as otherwise it'll still be added after the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a way you'd recommend making a test case to confirm what the output looks like? Right now I'm just relying on a test that confirms that the output compiles, but not what it actually looks like.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can use -dump-macro-expansions. There should be a few tests that do that today

Copy link
Contributor

Choose a reason for hiding this comment

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

@bnbarham i discussed with Zev, and i'll try to push this forward here: #84833 – i took a stab at incorporating your feedback and adding some filecheck tests of (a portion of) the macro output. would appreciate any further input!

bindings: bindings.privatePrefixed(prefix, in: context),
trailingTrivia: trailingTrivia
)
Expand Down
12 changes: 12 additions & 0 deletions test/stdlib/Observation/Observable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,18 @@ final class DeinitTriggeredObserver {
}
}

@Observable
final class CommentOnLineBeforeOtherAnnotation {
// This comment should not break the observation-ignored annotation added by the Observable macro.
@MainActor
var it = 0
}

@Observable
final class CommentOnSameLineAsOtherAnnotation {
@MainActor // This comment should not break the observation-ignored annotation added by the Observable macro.
var it = 0
}

@main
struct Validator {
Expand Down