-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional attributes fixes #88
Merged
apparentlymart
merged 3 commits into
zclconf:main
from
alisdair:optional-attributes-fixes
Mar 8, 2021
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing this check made me wonder if the shallow check here would be sufficient to deal with a case where we have a type constraint that only indirectly contains an object type with optional attributes. In order to try to test that I added the following test case in
public_test.go
, adapting one of the ones you added in this PR:Unfortunately this seems to fall into the same panic trap as the original upstream report 😖
I think unfortunately getting correct behavior here is going to require a recursive walk of the type constraint for any null value (and possibly also the same for ths
!in.IsKnown()
case above?) to concrete-ize any of the object types with optional attributes inside. The methodcty.Type.HasDynamicTypes
shows a pattern for implementing a recursive walk of that sort, so I guess my first idea is to addcty.Type.WithoutOptionalAttributesDeep
that will return a type with all of the optional attributes inside removed. That will unfortunately be a bit expensive for new memory allocation, but I think in a way that will have similar impact to the "normal" (non-null, known) type conversion codepaths.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apparentlymart I'm unable to reproduce this panic when both of the commits on this branch are in place. The extra unification step introduced for lists (and sets) handles the disjoint types of the
null
andobject
tuple members, and the result is that the test passes. If I revert the unification commit, the panic occurs.With unification in place, I can't see any situation where the
WithoutOptionalAttributesDeep
function is needed. I'm happy to add a commit to add and use it, but I'm not sure it's necessary until I can find a test case which fails without it.Am I missing something, or did you test the panic against the first commit only? Any suggestions for an extended test which would fail in this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @alisdair,
Curiously, I went back to my dev environment where I'd previously tested this and re-ran tests without any modifications and it didn't panic for me anymore either, so I have to assume I'd somehow got a stale result out of the test suite, although I have no concrete explanation as to why that would be.
Your explanation of how the unification step should get expected result makes sense to me now I re-read the changeset with that idea in mind, and I can no longer reproduce this panic, so instead of trying to explain this oddity I'm going to just assume I made a human error while I was testing and inadvertently tested something other than what I thought I was testing.
With that said, I made some adjustments to the test to take type unification out of the process and focus only on the type conversion aspect, with this new test case:
This failed for me because the resulting null value had a type still containing optional attributes:
Of course, we could decide that the
Want
value I wrote here is what's wrong, rather than the actual result, but given that in other cases we've decided that the result should have all of the optional attribute annotations removed, I wanted to raise this to see what you think about the inconsistency of this result.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the extra clarification! I think the most recent commit addresses this now, for both unknown and null values.