Skip to content

Provide tailored error and fix-it when result builder attribute is applied to type #64474

Open
@AnthonyLatsis

Description

@AnthonyLatsis

Swift adopted a lot of attributes over the years, and sometimes it can be hard to remember where an attribute is supposed to go. Here’s an example where the compiler fails to issue a helpful reminder:

@resultBuilder
struct Builder {
  static func buildBlock() {}
}

func foo(_: @Builder () -> Void) {} // error: unknown attribute 'Builder'

Result builder attributes are custom declaration attributes, so a much better diagnosis would be something along the lines of result builder attribute 'Builder' must be applied to the <declaration kind> instead plus a corresponding fix-it.


I suspect this problem is not exclusive to result builders. Prospectively, we should probably look into devising a general solution for diagnosing declaration attributes on types and vice versa.

Metadata

Metadata

Assignees

No one assigned

    Labels

    attributesFeature: Declaration and type attributescompilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationfix-itsFeature: diagnostic fix-itsimprovementresult buildersFeature: Result builders

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions