Member type of bare type variable bound to self-reference is`ResolvedRecursiveType` (unlike `T[]` or `List<T>`)
已經有一個關聯 PR 被合併了。
- #138 來自 @cowtowncoder —— 已合併
評估
研究方向
Start with TypeResolver.resolve(TypeBindings, Type) and its _completeType() helper, then compare with resolveSubtype(), which already uses _selfReferenceTarget(). Use MemberResolver and the reproduction's Sym/Base classes to see why the field value keeps a ResolvedRecursiveType while arr does not. Done when value resolves to a fully resolved type equal to the arr element type, and the existing tests still pass.
由索引模型根據 Issue 內容生成。
描述
When a member's type is a bare type variable bound to a self-reference, the resolved member type is a ResolvedRecursiveType (whose getParentClass() is null and getImplementedInterfaces() empty), whereas uses of the same variable within other types (T[], List<T>) resolve to fully resolved types.
Reproduction
public static class Base<X> { public X value; public X[] arr; }
public static class Sym<T extends Sym<T>> extends Base<T> { }
TypeResolver r = new TypeResolver();
ResolvedTypeWithMembers sym = new MemberResolver(r).resolve(r.resolve(Sym.class), null, null);
// field `value`: ResolvedRecursiveType `Sym<Object>`, getParentClass() == null
// field `arr`: element type is ResolvedObjectType `Sym<Sym<Object>>`
// -> value type not equal to `arr` element type
Same happens with raw self-references, like field X value of RB for RA<T extends RB> / RB extends Base<RA>.
On 1.7 / current main both value and arr element types are ResolvedRecursiveTypes (so they are at least consistent); with 1.8 (#128) incomplete types are re-resolved when obtained via TypeResolver.resolve(TypeBindings, Type) (as done by MemberResolver), except for bare self-references, which are left as-is.
Expected
Member type for value is a stand-alone (fully resolved) type, same as arr element type, so that member types can be navigated (parent class, interfaces) and compared consistently.
Notes
Likely fix: in TypeResolver.resolve(TypeBindings, Type) (_completeType()), replace a top-level self-reference with the type it represents (_selfReferenceTarget(), as resolveSubtype() already does). This changes member types that are currently ResolvedRecursiveTypes, so it is a behavioral change (although equality with fully resolved types is retained).
- 主要語言
- Java
- 星號
- 266
- 分支
- 53
- 平均合併
- 18 小時 46 分鐘
- 30 天內合併 PR
- 8
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
FasterXML/java-classmate 的其他 Issue
-
難度 5/5 一週以上 新手友好度 25/100
FasterXML/java-classmate#111 · 10 則留言 ·
-
難度 5/5 一週以上 新手友好度 20/100
FasterXML/java-classmate#81 · 1 則留言 ·
-
Make `GenericType<T>` not implement `java.lang.reflect.Type`可能已有人在做 @cowtowncoder 於 312 天前認領。 未關閉
難度 4/5 3-5 天 新手友好度 35/100
FasterXML/java-classmate#76 · 6 則留言 · 1 個 reaction ·
-
難度 5/5 一週以上 新手友好度 20/100
FasterXML/java-classmate#72 · 3 則留言 ·
-
難度 4/5 3-5 天 新手友好度 35/100
FasterXML/java-classmate#69 · 22 則留言 ·
查看 FasterXML/java-classmate 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 4 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
objectionary/lints#1556 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
wildfly/wildfly-launcher#99 ·
-
難度 2/5 1-3 小時 新手友好度 65/100
apache/rocketmq#11427 · 2 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
維護者通常 1 天內回覆