-
Notifications
You must be signed in to change notification settings - Fork 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
Add support for covariant returns #619
Merged
jonorossi
merged 8 commits into
castleproject:master
from
stakx:bugfix/covariant-returns
Jul 19, 2022
Merged
Add support for covariant returns #619
jonorossi
merged 8 commits into
castleproject:master
from
stakx:bugfix/covariant-returns
Jul 19, 2022
Commits on May 14, 2022
-
Configuration menu - View commit details
-
Copy full SHA for 9a84a79 - Browse repository at this point
Copy the full SHA 9a84a79View commit details -
Add failing test for proxying derived
record
typeOn .NET 6+ this fails with a `TypeLoadException`: > Return type in method `DerivedEmptyRecord.<Clone>$()` [...] is not > compatible with base type method `EmptyRecord.<Clone>$()` From dotnet/efcore#26602 (comment): > The C# compiler changed the emit strategy for records in .NET 6 to > take advantage of covariant returns. The Clone method now always has a > return type that matches the containing type. Covariant returns were > added to the runtime and language in .NET 5 but records didn't take > advantage of them (just ran out of time). In .NET 6 though we finished > off that feature and added it to records. So we'll need to add support for covariant returns to DynamicProxy.
Configuration menu - View commit details
-
Copy full SHA for 2cf79ee - Browse repository at this point
Copy the full SHA 2cf79eeView commit details -
Minimal bugfix: relax return type equality check
The previous commit's test fails due to DynamicProxy treating the base and derived record classes' `<Clone>$` methods as two distinct methods (because they differ in their exact return type), instead of as a single overridden method. We can change this by adjusting `MethodSignature- Comparer` such that it also accepts assignment-compatible return types.
Configuration menu - View commit details
-
Copy full SHA for d27ef43 - Browse repository at this point
Copy the full SHA d27ef43View commit details -
Check for
PreserveBaseOverridesAttribute
Covariant returns were introduced with .NET 5. For all earlier runtimes, the last commit may have relaxed method signature comparison too much. We can resolve this by checking for a specific custom attribute that .NET compilers are expected to put on override methods using covariant returns. Reference: https://github.com/dotnet/runtime/blob/main/docs/design/features/covariant-return-methods.md
Configuration menu - View commit details
-
Copy full SHA for 4bc7ba2 - Browse repository at this point
Copy the full SHA 4bc7ba2View commit details -
MethodSignatureComparer.Equals
should be commutativeSo far, we simply assumed that `x` := override method, and `y` := over- ridden method, but there is actually no guarantee for that.
Configuration menu - View commit details
-
Copy full SHA for 9ed7fa3 - Browse repository at this point
Copy the full SHA 9ed7fa3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 36c608a - Browse repository at this point
Copy the full SHA 36c608aView commit details -
Configuration menu - View commit details
-
Copy full SHA for cf8c602 - Browse repository at this point
Copy the full SHA cf8c602View commit details -
Configuration menu - View commit details
-
Copy full SHA for 01c2c6a - Browse repository at this point
Copy the full SHA 01c2c6aView commit details
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.