Open Anaminus opened 5 years ago
To properly generate a golden file for implementations that produce a default rather than discarding, a property can be marked as expecting a default, then the result can be compared against the default specified for the class. If equal, then the property is not written to the golden file, effectively discarding it.
For the Roblox implementation, a new instance of the class can be created to determine the default value of the property. Other such implementations are on their own.
How to mark the property?
Default would occur when a property fails to be parsed, and the failure propagation stops at the point where the value is to be set to the property of the initialized instance. On the other hand, Zero would occur when the failure propagation stops at the value. A component fails to be set to the initialized value, but the value still succeeds, so it is then successfully set to the property.
Roblox appears to have at least three kinds behaviors when a parsing failure occurs:
Hard
Parsing halts completely. An error message is usually displayed.
Default
Failing to parse a property results in a default value that is dependent on the property. Parsing continues as normal.
Example:
Part.CanCollide
, a bool, defaults totrue
. If parsing fails, the result istrue
.BoolValue.Value
defaults tofalse
. If parsing fails, then the result isfalse
.Zero
Failing to parse a property results in a value that is the "zero" or initialized value for the type. Parsing continues as normal.
Example:
Part.Color
, a Color3, defaults to163, 162, 165
. If parsing fails, then the result is0, 0, 0
.Representation
A hard-failure is represented by an error struct. The content of the golden error message doesn't matter much as long as it's distinct, and the program is able to detect the error and transform it into the expected message.
Default-failures are difficult to get exactly right, because it requires additional metadata which is not readily available, and so may not be supported by 3rd-party implementations. This could be resolved by discarding the property entirely, which retains the distinction from zero-failures: