Skip to content

Fatal error on incorrect usage #6

@gohanlon

Description

@gohanlon

Description

On swift-macro-testing 0.2.0 and main, the following error in assertMacro usage results in a crash:

    assertMacro {
      """
      @MemberwiseInit
      public struct Pedometer {
        var stepsToday = 0
      }
      """
    } expansion: {
      """
      @MemberwiseInit
      public struct Pedometer {
        var stepsToday = 0
            ┬─────────────
            ╰─ 🛑 @MemberwiseInit requires explicit type declarations for `var` stored properties.
      }
      """
    }

My user error was to use the label expansion: instead of diagnostics:. The crash happens deep into the SyntaxVisitor.walk due to an unsafe unwrap. Every one of my tests exercising a diagnostic had this user error and resulted in the same crash.

I discovered this while updating my tests to 0.2.0, using an overly naive find/replace from "matches" to "expansion", having eschewed the given "re-record" advice.

This strikes me as a Swift Syntax issue: I don't think Swift Syntax's RawSyntaxChildren is ever intended to ever fatal error, even on bad input. Thoughts?

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 (3c9424a)

Destination operating system

No response

Xcode version information

Xcode Version 15.0 (15A240d)

Swift Compiler version information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions