Skip to content

fix: strip backticks from coding keys of escaped identifiers - #48

Merged
vnixx merged 1 commit into
mainfrom
fix/escaped-identifier-coding-key
Dec 1, 2026
Merged

vnixx merged 1 commit into
mainfrom
fix/escaped-identifier-coding-key

Conversation

@vnixx

@vnixx vnixx commented Dec 1, 2026

Copy link
Copy Markdown
Member

Fixes #47

Problem

Escaped identifiers used their backticked source spelling as coding keys:

@Codable
struct Model {
    var `class`: Int?   // key was "`class`", so {"class":1} decoded to nil
}

The same issue affected enums: case names (case \default`), String raw values, associated value labels, and @CodingCase(values: [.label("class", ...)])` failed macro expansion.

Fix

  • Keep the source spelling (name / caseName / variableName) for generated Swift code.
  • Add a derived keyName (backticks stripped) on PropertyInfo, EnumCase, and AssociatedValue, and use it everywhere a coding key, raw value, or case-style conversion is built.

Tests

EscapedIdentifierTests covers optional/required properties, @CodingKey, @SnakeCase, String/plain/associated enums, case styles on enums, and @CodingCase label matching. All tests pass.

Escaped identifiers such as `class` / `default` used their backticked
source spelling as coding keys, so {"class":1} decoded to nil.

Keep the source spelling for generated Swift code and derive an
unescaped keyName for coding keys in PropertyInfo, EnumCase and
AssociatedValue. This covers properties, case styles, enum raw values,
enum case keys, associated value labels and @CodingCase .label matching.

Fixes #47
@vnixx
vnixx merged commit 0f3e8c6 into main Dec 1, 2026
2 checks passed
@vnixx
vnixx deleted the fix/escaped-identifier-coding-key branch December 1, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

系统关键字同名属性名字解码不成功问题

1 participant