[Bug] @CodedAt with enum with labeled associated values produces compile time warnings
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 68/100
Direzione di ricerca
Inizia leggendo l’espansione della macro mostrata nell’issue e segui come @CodedAt genera la condizione di decodifica per i valori associati etichettati. Compila l’enum fornito con Swift 6 e conferma l’avviso relativo a container non utilizzato. Il lavoro è completato quando il codice generato per questo input valido viene compilato senza quell’avviso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
- I have read the documentation.
- I have read the limitations.
- I could not find my issue.
Hi, it seems that #167 introduced new compile time warning for enums with labeled associated values, for example following code now produces warning - Immutable value 'container' was never used; consider replacing with '_' or removing it
@Codable
@CodedAt("type")
enum TypeObject {
case type1(number: Int)
}
To Reproduce
Steps to reproduce the behavior:
- Create project with following
enum
@Codable
@CodedAt("type")
enum TypeObject {
case type1(number: Int)
}
- build
Expected behavior
MetaCodable should generate code that does not produce Swift compiler warnings (especially unused variable warnings) for valid inputs.
Environment (please complete the following information, remove ones not applicable):
- OS: macOS
- Version 27
- Xcode 27.2
- Swift 6
Additional context
expanded macro:
extension TypeObject: Decodable {
init(from decoder: any Decoder) throws {
var typeContainer: KeyedDecodingContainer<CodingKeys>?
let container = try? decoder.container(keyedBy: CodingKeys.self)
if let container = container {
typeContainer = container
} else {
typeContainer = nil
}
if let typeContainer = typeContainer, let container = container { // this `let container` produces warning
let typeString: String?
do {
typeString = try typeContainer.decodeIfPresent(String.self, forKey: CodingKeys.type) ?? nil
} catch {
typeString = nil
}
if let typeString = typeString {
switch typeString {
case "type1":
let number: Int
let container = try decoder.container(keyedBy: CodingKeys.self)
number = try container.decode(Int.self, forKey: CodingKeys.number)
self = .type1(number: number)
return
default:
break
}
}
}
let context = DecodingError.Context(
codingPath: decoder.codingPath,
debugDescription: "Couldn't match any cases."
)
throw DecodingError.typeMismatch(Self.self, context)
}
}
extension TypeObject: Encodable {
func encode(to encoder: any Encoder) throws {
let container = encoder.container(keyedBy: CodingKeys.self)
var typeContainer = container
switch self {
case .type1(number: let number):
try typeContainer.encode("type1", forKey: CodingKeys.type)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(number, forKey: CodingKeys.number)
}
}
}
extension TypeObject {
enum CodingKeys: String, CodingKey {
case type = "type"
case number = "number"
}
}
- Lingua principale
- Swift
- Stelle
- 779
- Fork
- 46
- Merge medio
- 9h 7m
- PR unite (30g)
- 2
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di SwiftyLab/MetaCodable
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
SwiftyLab/MetaCodable#82 · 6 commenti ·
-
enhancement good first issue
Difficoltà 4/5 3-5 giorni Idoneità per principianti 32/100
SwiftyLab/MetaCodable#49 · 5 commenti · 2 reazioni ·
Tutte le issue di SwiftyLab/MetaCodable
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
521xueweihan/HelloGitHub#4131 ·
-
[Bug] Error: thaw@beta: thaw@beta: This cask does not run on macOS versions older than Golden Gate.Apertamacos-27 ops
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
thaw-app/Thaw#1400 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ParetoSecurity/pareto-mac#324 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
duongductrong/Snapzy#691 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100