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
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.
Given the following code (note the instance property is now a var instead of a let):
The following output is produced:
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.
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.
To circumvent the issue, add in manual support of Decodable.