-
Notifications
You must be signed in to change notification settings - Fork 19
Fix ReflectionProvider bug on inheritance #470
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
Open
Daniel-Svensson
wants to merge
4
commits into
eiriktsarpalis:main
Choose a base branch
from
Daniel-Svensson:inheritance_problem
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
14f7867
Fix: System.InvalidOperationException : The declared derived type 'a'…
Daniel-Svensson e1edf44
Simplify where
Daniel-Svensson 53b7c7e
Apply suggestion from @Daniel-Svensson
Daniel-Svensson 3fe9bcc
Update src/PolyType/ReflectionProvider/ReflectionTypeShapeProvider.cs
Daniel-Svensson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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.
How does this test for the bug you fixed?
Uh oh!
There was an error while loading. Please reload this page.
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.
Getting the type shape for cat would throw InvalidOperationException. saying that Dog is not assignable to Cat
It would never reach the asserts.
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.
I did not see any similar testcases for DerivedTypeShapeAttributes, if you want separate tests to verify DerivedTypeShapeAttributes please give some advice on where they make sense to add
Uh oh!
There was an error while loading. Please reload this page.
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.
Can't you use Assert.Throws?
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.
@eiriktsarpalis can you please elaborate a bit, I am new to xunit, why would I use Assert.Throws to check that a method call does not throw ?
I verified that the test fails without the code fix, since GetTypeShape would throw an an exception.
In addition I check the union cases to match
KnownTypeAttribute_ReportsUnionShapeabove since originally all cases from the base class was discovered and added, so It would guard against Cat beeing a union case.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.
Ok, I understood you had said the opposite. As mentioned in #470 (comment) I would still prefer it if we threw an exception in this case to make sure user misconfiguration is caught immediately.
Uh oh!
There was an error while loading. Please reload this page.
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.
Ok, I think there is some confusion since the PR did 2 things.
The test verifies that the following works with both KnownType (the same problem is fixed for DerivedType as well) attributes. The problem only affected ReflectionProvider but works with
GenerateShapeAttribute.Note that the attributes for "PersianCat" is applied to both "Animal" and "Cat ", (which is not required by DataContractSerializer) but match what is required by json attributes and the PolyType DerivedType when used with source generator. Which is how I understand you want it to work.