Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Swift: clear a field's preserved unknown enum value from unknownFields when the field is mutated

Aperta
#3,710 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
52/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
kotlin, swift
Ambito
tooling

Direzione di ricerca

Inizia dal comportamento delle proprietà generate a livello di generatore descritto nell’issue e analizza #3708, quindi esegui testEditedSingularEnumFieldReemitsPreservedUnknownValue. Segui l’inizializzazione di ProtoDecoder e il percorso di assegnazione generato, in modo che la cancellazione sia limitata alla mutazione dell’utente, non a decode/init. Il lavoro è completato quando i campi enum singolari, ripetuti e map modificati non emettono più i relativi valori sconosciuti preservati, mentre il decoding continua a preservarli.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Tracked follow-up from #3708 (see the review discussion there).

Context

#3708 makes ProtoDecoder's .returnNil strategy preserve unrecognized singular enum values in the message's unknownFields, matching what repeated/map enum fields, generated Kotlin/Java, and proto2 semantics already do.

Preservation has a flip side, shared by all of those existing implementations: a client that mutates the unknown-valued enum field itself reencodes [known value][preserved unknown], and last-wins readers keep the unknown value — the client's edit is shadowed until it learns the new enum case. In Swift this is pinned by testEditedSingularEnumFieldReemitsPreservedUnknownValue.

Proposal

Generator-level clear-on-mutate: generated messages clear the corresponding unknownFields entry when a field is set — e.g. a didSet on the generated property, guarded so it does not fire during decode/init (where the decoder legitimately populates both the field and unknown fields). The generator knows each field's tag, so it can scope the clear precisely.

A generator-level shape is preferred over a runtime-only one (e.g. ProtoWriter skipping preserved values when the typed field is non-nil) because only the generator can distinguish "user mutated this field" from "decoder populated it", and because the same shadowing applies to repeated and map enum fields, where the writer can't safely tell a user-updated collection from a decoded one.

Notes
  • This is longstanding cross-platform behavior — generated Kotlin/Java and protobuf proto2 runtimes shadow the same way — so this would be an improvement over parity, not a regression fix. If pursued, it's worth deciding whether Kotlin/Java want the equivalent (builder/copy-level clearing).
  • A related singular-enum generator edge is disclosed in #3708: when the same singular enum tag occurs twice on the wire as [known, unknown], generated Swift assigns each decode result unconditionally, so the later unknown occurrence overwrites the known value with nil (generated Kotlin's catch skips the assignment). A fix there (skip assignment when the decode returns nil) is the same neighborhood of generated code and could ride along.

🤖 Filed by Logan's AI agent per the review discussion on #3708.

Lingua principale
Kotlin
Stelle
4.4k
Fork
633
Merge medio
1g 16h
PR unite (30g)
10

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di square/wire

Tutte le issue di square/wire

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.