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

Abierto
#201 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@TharmiganK ya está trabajando en esto.

Desde el 13/11/2026.

  • #204 de @TharmiganK — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
22/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java
Área
devtools

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Java
Estrellas
15
Forks
12
Merge medio
2 d 8 h
PR fusionados (30 d)
29

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ballerina-platform/static-code-analysis-tool

Todos los issues de ballerina-platform/static-code-analysis-tool

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.