[Bug] @CodedAt with enum with labeled associated values produces compile time warnings
還沒有人認領這個 Issue。
評估
研究方向
首先閱讀 issue 中展示的巨集展開,並追蹤 @CodedAt 如何為帶標籤的關聯值產生解碼條件。使用 Swift 6 建置提供的 enum,並確認出現了 container 未使用的警告。對於這個有效輸入,產生的程式碼能在沒有該警告的情況下建置,即為完成。
由索引模型根據 Issue 內容生成。
描述
- 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"
}
}
- 主要語言
- Swift
- 星號
- 779
- 分支
- 46
- 平均合併
- 9 小時 7 分鐘
- 30 天內合併 PR
- 2
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
SwiftyLab/MetaCodable 的其他 Issue
-
enhancement
難度 4/5 3-5 天 新手友好度 35/100
SwiftyLab/MetaCodable#82 · 6 則留言 ·
-
enhancement good first issue
難度 4/5 3-5 天 新手友好度 32/100
SwiftyLab/MetaCodable#49 · 5 則留言 · 2 個 reaction ·
查看 SwiftyLab/MetaCodable 的全部 Issue
相似的 Issue
-
simulator-session.yml の simtunnel の固定先が古く、agentd が無いため simtunnel up --wait / status が準備完了を検知できない未關閉
難度 2/5 1-3 小時 新手友好度 68/100
-
難度 1/5 1-3 小時 新手友好度 85/100
apache/arrow-swift#203 ·
-
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆
-
RealtimeV2 fails to compile on Xcode 27.1 / Swift 6.4: ambiguous implicit access level for import of 'HTTPTypes'可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉Realtime swift
難度 2/5 1-3 小時 新手友好度 68/100
supabase/supabase-swift#1647 ·
維護者通常 1 天內回覆
-
[Pri] Low [Status] Ready for Dev [Type] Bug /Me
難度 2/5 1-3 小時 新手友好度 78/100
wordpress-mobile/WordPress-iOS#26279 · 1 則留言 ·
維護者通常 1 天內回覆