Skip to content
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

Fix-it coverage lost when macros include diagnostics with and without fix-its #19

Open
2 tasks done
gohanlon opened this issue Jan 12, 2024 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working

Comments

@gohanlon
Copy link
Contributor

Description

assertMacro only applies fix-its when all emitted diagnostics have one or more fix-its, so fix-it coverage is lost when macros include diagnostics with and without fix-its. Instead, fixes should be included if any diagnostic has fix-its, even though it’s probable that the fixed source won’t resolve all the diagnostics. (I say “probable” because it is possible, yet unusual, for one fix-it to resolve multiple diagnostics.)

Currently, the following test:

func testInvalidLabelAndDefaultOnMultipleBindings() {
  assertMacro {
    """
    @MemberwiseInit
    struct S {
      @Init(default: 0, label: "$foo") let x, y: T
    }
    """
  }
}

records with just diagnostics:

func testInvalidLabelAndDefaultOnMultipleBindings() {
  assertMacro {
    """
    @MemberwiseInit
    struct S {
      @Init(default: 0, label: "$foo") let x, y: T
    }
    """
  } diagnostics: {
    """
    @MemberwiseInit
    struct S {
      @Init(default: 0, label: "$foo") let x, y: T
                        ┬────────────
            │           ╰─ 🛑 Custom 'label' can't be applied to multiple bindings
            ┬──────────
            ╰─ 🛑 Custom 'default' can't be applied to multiple bindings
               ✏️ Remove 'default: 0'
    }
    """
  }
}

I'd expect that the following fixes closure would be included after diagnostics:

[…]
  } fixes: {
    """
    @MemberwiseInit
    struct S {
      @Init(label: "$foo") let x, y: T
    }
    """
  }

Checklist

  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

swift-macro-testing version information

0.2.0, main (15916c0)

Destination operating system

macOS 14.2

Xcode version information

Xcode Version 15.1 (15C65)

Swift Compiler version information

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0
@gohanlon gohanlon added the bug Something isn't working label Jan 12, 2024
@gohanlon
Copy link
Contributor Author

gohanlon commented Jan 12, 2024

This can be addressed incrementally, but is also discussed in #18 (a comprehensive proposal).

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

No branches or pull requests

1 participant