Skip to content

[Macros] Copy attrs/modifiers on MacroExpansionDecl to expanded decls #1666

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 3 commits into from
May 16, 2023

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented May 15, 2023

As per the SE-0397 amendment, copy attributes and modifiers on MacroExpansionDecl to the expanded declarations.

Preparation:

  • Rename AttributedSyntax to WithAttributesSyntax.
  • Keep AttributedSyntax as a typealias to WithAttributeSyntax
  • Introduce WithModifiersSyntax
  • Add init(_: [Element]) to SyntaxCollection's requirements

@rintaro
Copy link
Member Author

rintaro commented May 15, 2023

@swift-ci Please test

@@ -27,6 +27,7 @@ add_swift_host_library(SwiftParser
Specifiers.swift
Statements.swift
StringLiterals.swift
StringLiteralRepresentedLiteralValue.swift
Copy link
Member Author

Choose a reason for hiding this comment

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

Oh this is now unrelated to this PR. I wanted to use this feature (representedLiteralValue ) in swift repo test cases, but ended up with not using it because the compiler doesn't support @freestanding(declaration, names: arbitrary) macros.

But this was missing anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for noticing and fixing 🙏🏽

@@ -27,6 +27,7 @@ add_swift_host_library(SwiftParser
Specifiers.swift
Statements.swift
StringLiterals.swift
StringLiteralRepresentedLiteralValue.swift
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for noticing and fixing 🙏🏽

@@ -1037,4 +1058,39 @@ final class MacroSystemTests: XCTestCase {
indentationWidth: indentationWidth
)
}

func testDeclsFromStringLiterals() {
assertMacroExpansion(
Copy link
Member

Choose a reason for hiding this comment

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

As with my comment in your other PR, I would really prefer this to be three different assertMacroExpansion calls, each only having a single #decl macro expansion. It just makes debugging so much easier if the test case fails.

Test 1

struct S {
  public #decls(
    """
    static func foo() {
    print("value") }
    """,
    "struct Inner {\n\n}"
  )
}

Test 2

struct S {
  @attr static #decls("var value1 = 1", "typealias A = B")
}

Test 3

@attribute
@otherAttribute(x: 1) #decls("@moreAttibute var global = 42")

@rintaro rintaro force-pushed the macrodecl-attribute-expansion branch from 06e6de2 to d7d7a09 Compare May 16, 2023 03:29
@rintaro
Copy link
Member Author

rintaro commented May 16, 2023

@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented May 16, 2023

@swift-ci Please test Windows

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