You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
swift-ci opened this issue
Mar 5, 2019
· 6 comments
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.CodableArea → standard library: `Codable` and co.compilerThe Swift compiler in itself
Swift fails to understand that Decodable synthesis should only take into account instance property names and should ignore static property names. By having an instance property and static property with the same name, it confuses the compiler into not adding the Decodable synthesis for that particular property.
If the static property name is changed then Decodable synthesis works correctly.
Variation 2
Given the following code (note the instance property is now a var instead of a let):
This is arguably a worse result as it is not found at compile time and only found at run time. This means that code that should work at first glance and that passes compilation doesn't produce the expected output.
Expected Result
I would expect that the struct conformance to Decodable would be correctly synthesised and the static property name would be ignored. Failing that I would at least expect the decoding of the instance property to throw an error at runtime if it manages to compile, but this isn't the case.
The most desirable result would for Decodable synthesis to be correctly applied.
Workaround
To circumvent the issue, add in manual support of Decodable.
requiredinit(decoder: Decoder) throws { ... }
The text was updated successfully, but these errors were encountered:
@AnnaZaks I have verified this is fixed in Xcode 11 Beta 5 (11M382q) running Swift 5.1. Thanks for the speedy turn around on this brentdax (JIRA User).
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.CodableArea → standard library: `Codable` and co.compilerThe Swift compiler in itself
Environment
Originally found on Swift 4.2.2 running on Ubuntu 18.04
Reproduced on Swift 4.2 running on macOS 10.14.3
Reproduced on Swift 5 beta 4 running on macOS 10.14.3
Additional Detail from JIRA
md5: 5dcbaff73a6035f1ffe58c76cc81c5b1
Issue Description:
Details
Variation 1
Given the following code:
The following error is produced:
Swift fails to understand that Decodable synthesis should only take into account instance property names and should ignore static property names. By having an instance property and static property with the same name, it confuses the compiler into not adding the Decodable synthesis for that particular property.
If the static property name is changed then Decodable synthesis works correctly.
Variation 2
Given the following code (note the instance property is now a var instead of a let):
The following output is produced:
nil
This is arguably a worse result as it is not found at compile time and only found at run time. This means that code that should work at first glance and that passes compilation doesn't produce the expected output.
Expected Result
I would expect that the struct conformance to Decodable would be correctly synthesised and the static property name would be ignored. Failing that I would at least expect the decoding of the instance property to throw an error at runtime if it manages to compile, but this isn't the case.
The most desirable result would for Decodable synthesis to be correctly applied.
Workaround
To circumvent the issue, add in manual support of Decodable.
The text was updated successfully, but these errors were encountered: