Property accesses in failed expectations sometimes include their value twice in expanded description #601
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
#expector 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
keyPathassociated value of the__Expression.Kind.propertyAccessenum case is an__Expressionand 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 storingkeyPathas an expression and expanding it is redundant. The source code ofkeyPathneeds 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
functionCallenum case.Modifications:
keyPathassociated value of__Expression.Kind.propertyAccessto be aStringcontaining the name of the property, rather than an__Expression.#expectand similar macros to emit the property name as a string literal rather than an__Expressionfactory function.Result:
The two examples given above no longer include the property value twice.
Checklist: