ballerina:2 reports methods of an object constructor that initializes a typed class field

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

维护者通常 1 天内回复

@TharmiganK 已经在做这个了。

开始于 2026年11月13日。

  • #204 来自 @TharmiganK —— 未关闭

评估

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

调研方向

Start with StaticCodeAnalyzer.contextualTypes, which has no case for ObjectFieldNode and falls back to semanticModel.expectedType. Run bal scan field.bal on the reproduction in the issue to confirm that line 7 is reported and line 12 is not. Done means the class-field object constructor is no longer flagged while the existing rule tests still pass. Pull request #204 is already open against this issue, so check it before starting.

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

描述

Area/Rules Type/Bug
Area

Rules

Description

ballerina:2 should not report the parameters of methods that implement a method of the type of an object constructor (#169, #173 and the 0.11.x backport #182). When the object constructor initializes a typed class field, the parameter is still reported. The same constructor, typed by the same object type, is not reported as a module variable, local variable, return value, argument, assignment, record field or expression body. An anonymous function in a class field initializer (final BinOp f = function(int a, int b) ...) is not reported either.

Likely cause, from reading the source (not verified): StaticCodeAnalyzer.contextualTypes has no case for ObjectFieldNode and falls back to semanticModel.expectedType(document, startLine), which does not give the field's type for an object constructor.

Found while testing v0.14.0 (#186) and v0.11.2 (#187).

Steps to Reproduce

field.bal:

type Op object {
    function m(int p) returns int;
};

class Holder {
    final Op viaField = object {
        function m(int p) returns int => 1;
    };
}

Op viaModule = object {
    function m(int p) returns int => 1;
};

public function main() {
    _ = new Holder();
    _ = viaModule;
}

Run bal scan field.bal.

Expected Behavior

No issues: both m methods implement Op.m, so their signatures are fixed by the type.

Actual Output
[('ballerina:2', 7)]

Line 7 (the class field) is reported; line 12 (the module variable) is not.

Ballerina Version

2201.12.0 (scan 0.11.2); 2201.13.2 and 2201.14.1 (scan 0.14.0)

Scan Tool Version

0.14.0 and 0.11.2 (DEV Central)

Environment

macOS

主要语言
Java
星标
15
派生
12
平均合并
2 天 8 小时
30 天内合并 PR
29

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

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

ballerina-platform/static-code-analysis-tool 的其他 Issue

查看 ballerina-platform/static-code-analysis-tool 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

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