Property accesses in failed expectations sometimes include their value twice in expanded description #601
+78
−23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a bug in which some property access expressions passed to
#expect
or other expectations will include their value twice, redundantly, in the expanded description if they fail.Here are two examples showing the expanded description before and after this fix:
The problem is that the
keyPath
associated value of the__Expression.Kind.propertyAccess
enum case is an__Expression
and recursively expanding it includes its runtime value. However, the overall property access is an expression too, and when it gets expanded, it includes that same value. So storingkeyPath
as an expression and expanding it is redundant. The source code ofkeyPath
needs to be stored, but it doesn't need to be an__Expression
.Conceptually, property accesses should be modeled more like function calls: the result of a function call expression is not stored as associated value of the
functionCall
enum case.Modifications:
keyPath
associated value of__Expression.Kind.propertyAccess
to be aString
containing the name of the property, rather than an__Expression
.#expect
and similar macros to emit the property name as a string literal rather than an__Expression
factory function.Result:
The two examples given above no longer include the property value twice.
Checklist: