Java printer: an Outer.this qualifier on a call is dropped, so the call binds to the inner class's method
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start by tracing javaInspector.print2 and the Java call-printing logic; the issue gives no source file or test name. Reproduce the example and inspect the printed source to find where the Outer.this qualifier is lost. Done means the qualifier is retained when needed to resolve the call correctly, with a regression test showing the output compiles.
由索引模型根据 Issue 内容生成。
描述
In an anonymous or inner class, a call qualified by the enclosing instance (Outer.this.m(..)) prints as a bare m(..). When the inner class has a method of the same name, the printed call means another method: it no longer compiles or, when the argument types fit, silently calls the wrong one.
package a.b;
import java.util.List;
abstract class X<T> {
abstract void apply(StringBuilder b, T value);
final X<List<T>> iterable() {
return new X<List<T>>() {
@Override
void apply(StringBuilder b, List<T> values) {
if (values == null) return;
for (T value : values) {
X.this.apply(b, value);
}
}
};
}
}
javaInspector.print2(cu, null, javaInspector.importComputer(4, cu.sourceSet())) prints the loop as
for (T value : values) { apply(b, value); }
which resolves to the anonymous class's own apply(StringBuilder, List<T>), and javac rejects it. The qualifier has to stay when the simple name would find a member of a nearer class, as with an explicit Outer.this the source wrote.
Found re-parsing printed sources of retrofit (ParameterHandler.iterable() and array(): ParameterHandler.this.apply(builder, value)); the unit is dropped. Related to #106 (other qualifiers a call needs).
maddi 0.9.6-alpha.4.
- 主要语言
- Java
- 星标
- 1
- 派生
- 1
- 平均合并
- 1 小时 55 分钟
- 30 天内合并 PR
- 8
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
CodeLaser/maddi 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
build/ci good first issue
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 67/100
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 68/100
维护者通常 1 天内回复
-
Java printer: a nested type prints by simple name when the unit imports another type of that name未关闭bug
难度 3/5 1-2 天 新手友好度 57/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
quarkiverse/quarkus-google-cloud-services#1188 ·
维护者通常 1 天内回复
-
Component: Frontend Component: Web Component Type: Maintenance
难度 2/5 1-3 小时 新手友好度 76/100
it-at-m/refarch-templates#1944 ·
维护者通常 2 天内回复
-
priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 68/100
googleapis/java-genai#1372 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 60/100