Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Import computer: a type used only as a constructor call's type argument (var x = new Box<Sol>()) is not imported

未关闭
#178 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
67/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java

调研方向

Start by locating javaInspector.importComputer and the code that collects types used by constructor calls; the issue reproduces the omission with new Box<Sol>(4) when assigned to var. Run the reproduction through javaInspector.print2 and check that the output includes import a.c.Sol; and compiles with javac. The issue names no test file, so first look for existing import computer tests and add the case there.

由索引模型根据 Issue 内容生成。

描述

bug

A type that a unit uses only as a type argument of a constructor call, as in var x = new Box<Sol>(4), loses its import: the import computer does not collect it.

package a.c;
public class Sol { }
package a.b;
public class Box<S> { public Box(int i) { } }
package a.b;
import a.c.Sol;
public class V {
    Object m() {
        var box = new Box<Sol>(4);
        return box;
    }
}

javaInspector.print2(cu, null, javaInspector.importComputer(4, cu.sourceSet())) prints

package a.b;
public class V { Object m() { var box = new Box<Sol>(4); return box; } }

without import a.c.Sol;, and javac rejects it. With var, the constructor call's type arguments are the only place the type is written, so nothing else brings the import in.

Found re-parsing printed sources of timefold-solver, where this is a common style: var termination = new MoveCountTermination<TestdataSolution>(4), var map = new HashMap<Class<?>, Set<Object>>(), new LinkedHashMap<Class<?>, List<AbstractRootNode<?>>>(), ... 10 units are dropped for it in one run (TestdataSolution, Set, List, ConstraintMetaModel, MoveSelector, TestdataListSolution).

maddi 0.9.6-alpha.4.

主要语言
Java
星标
1
派生
1
平均合并
1 小时 55 分钟
30 天内合并 PR
8

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

CodeLaser/maddi 的其他 Issue

查看 CodeLaser/maddi 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。