Skip to content

Support Covariant Return Types#334

Open
huoshan12345 wants to merge 25 commits into
dotnetcore:masterfrom
huoshan12345:feature/support-covariant-return-types
Open

Support Covariant Return Types#334
huoshan12345 wants to merge 25 commits into
dotnetcore:masterfrom
huoshan12345:feature/support-covariant-return-types

Conversation

@huoshan12345
Copy link
Copy Markdown
Collaborator

@huoshan12345 huoshan12345 commented Jul 20, 2025

Key Changes:

  • Support for Covariant Return Types
  • Typo Corrections
  • sign the project AspectCore.Tests to test internal methods

What is Covariant Return Types

see https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/covariant-returns

@huoshan12345 huoshan12345 changed the title Support covariant return types Support Covariant Return Types Jul 20, 2025
@huoshan12345 huoshan12345 marked this pull request as draft July 20, 2025 23:04
@huoshan12345 huoshan12345 marked this pull request as ready for review July 22, 2025 15:14
…mework into feature/support-covariant-return-types

# Conflicts:
#	src/AspectCore.Core/Utils/ProxyGeneratorUtils.cs
@huoshan12345 huoshan12345 marked this pull request as draft May 13, 2026 17:13
@huoshan12345 huoshan12345 marked this pull request as ready for review May 13, 2026 22:15
@liuhaoyang
Copy link
Copy Markdown
Member

阻塞问题评审意见

此 PR 合并前需要解决以下两个阻塞问题:

问题 1:多层协变返回继承链无法确定性地解析到叶子重写

涉及文件

  • src/AspectCore.Core/Extensions/TypeExtensions.cs
  • src/AspectCore.Core/DynamicProxy/ProxyBuilder/Builders/ClassProxyAstBuilder.cs
  • src/AspectCore.Core/DynamicProxy/ProxyBuilder/Builders/InterfaceImplAstBuilder.cs

核心问题:在 Base -> Mid -> Leaf 这样存在多次窄化重写链中,辅助方法可能对同一个基槽返回多个候选,但构建器使用 FirstOrDefault(...)` 取第一个,没有确保选择最派生的终止重写。

为什么阻塞:代理生成可能绑定到中间重写而非最派生实现,且行为可能依赖于不同运行时的反射枚举顺序。


问题 2:泛型方法协变返回匹配仍未支持

涉及文件

  • src/AspectCore.Core/Extensions/TypeExtensions.cs
  • tests/AspectCore.Tests/Extensions/CovariantReturnTests.cs

核心问题:泛型参数比较使用引用相等,但被重写的泛型方法具有不同的泛型参数 Type 实例,因此逻辑上等价的签名无法匹配。

重要细节:新增的名为泛型覆盖的测试实际上测试的是泛型类型上的非泛型方法,而非泛型方法重写。

为什么阻塞:具有协变返回的泛型虚/接口方法用户仍可能无法命中特化实现。


建议补充的回归测试方向

  1. 多层协变窄化(multi-level covariant narrowing)
  2. 带协变返回的泛型方法重写(generic method override with covariant returns)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants