Skip to content

Deprecated variables used in generated inits, could the init be marked deprecated as well? #932

Open

Description

@StianFlatby

Question

When a struct includes a deprecated variable, the generated variable correctly gets a @available(*, deprecated) notation. However, the struct also gets an autogenerated init which uses this deprecated variable, and is not itself marked as deprecated, thus generating a workspace-wide warning message.

Image

I was initially hoping you could just autogenerate a pragma silence to the specific line in the init that uses the deprecated value, but I now realize it's not possible to do so in Swift.
However - if the entire init is marked as deprecated, it would silence the use within.

Image

I don't know, maybe this just moves the problem elsewhere, or maybe it's better with one deprecated init (including all deprecated variables) and one non-deprecated init that just omits the deprecated variabels and just don't set them (as long as they are optional, I think they should implicitly resolve to nil without warnings?)

I'm not sure what's best, I'm just sad about the warnings we're getting.

Activity

  1. added
    status/triageCollecting information required to triage the issue.
    kind/supportAdopter support requests.
    on Aug 6, 2026
  2. czechboy0 commented on Aug 6, 2026

    @czechboy0
    Contributor

    Hi @StianFlatby,

    yeah this is a genuine problem.

    I don't know, maybe this just moves the problem elsewhere, or maybe it's better with one deprecated init (including all deprecated variables) and one non-deprecated init that just omits the deprecated variabels and just don't set them (as long as they are optional, I think they should implicitly resolve to nil without warnings?)

    Some sort of two variants of inits, one with all properties, one with only non-deprecated properties would be doable, I agree.

    However, I'm also not sure what we'd do about deprecated required properties.

  3. added
    kind/bugFeature doesn't work as expected.
    area/generatorAffects: plugin, CLI, config file.
    and removed
    status/triageCollecting information required to triage the issue.
    kind/supportAdopter support requests.
    on Aug 6, 2026
  4. KyawTheMonkey commented on Sep 18, 2026

    @KyawTheMonkey

    Hi @czechboy0, I’d love to take this on and put together a PR for it. Just wanted to check if anyone is currently working on it, if not, could you please assign it to me?

  5. czechboy0 commented on Sep 18, 2026

    @czechboy0
    Contributor

    Hi @KyawTheMonkey,

    before you spend time on the PR, can you first outline your approach?

  6. KyawTheMonkey commented on Sep 19, 2026

    @KyawTheMonkey

    Sure @czechboy0. Here's what I thought.

    • If there are no deprecated properties, the output remains unchanged. The majority of documents will be untouched.

    • If all deprecated properties are omitable (i.e., optional or carrying a schema default), we emit two initialiser variants

      • An initialiser containing all properties.
      • A clean initialiser containing only non-deprecated properties.
    • A deprecated property that is non-optional but carries a schema default must be assigned directly at the property declaration so the clean initialiser can omit it.

    • If there is at least one deprecated required property (regardless of any deprecated optional properties), we emit only the full initialiser, marked as deprecated. A clean initialiser cannot be provided here, as a value must still be supplied for the required field. Marking this sole initialiser as deprecated makes it explicit that the type cannot be constructed without touching a deprecated field. This still resolves the original issue by shifting the compiler warning out of the generated code and onto the adopter's call site, where they can address it.

    Anyone building with warnings-as-errors and passing a deprecated argument would newly fail. Would you prefer this behind a flag for a release or two, or is a 1.x minor acceptable given nothing stops compiling?

    Happy to adjust any of the above before I write the PR.

  7. czechboy0 commented on Sep 19, 2026

    @czechboy0
    Contributor

    So currently we don't generate defaults, that's tracked by #66

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/generatorAffects: plugin, CLI, config file.kind/bugFeature doesn't work as expected.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions