ballerina:2 reports methods of an object constructor that initializes a typed class field
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 22/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Java
- Stars
- 15
- Forks
- 12
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 29
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ballerina-platform/static-code-analysis-tool
-
Area/Configuration Type/Improvement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ballerina-platform/static-code-analysis-tool#217 ·
Maintainers usually reply within 1 day
-
Use the released ballerina/scan 1.0.0 on the 0.11.x linePossibly taken A pull request linked to this issue is open or already merged. OpenArea/Build Type/Task
Difficulty 1/5 Under an hour Newbie friendliness 72/100
ballerina-platform/static-code-analysis-tool#200 · 1 comment ·
Maintainers usually reply within 1 day
-
Clarify the breaking location change and the password placeholder exception in the 0.14.0 changelogPossibly taken A pull request linked to this issue is open or already merged. OpenType/Docs
Difficulty 1/5 1-3 hours Newbie friendliness 74/100
ballerina-platform/static-code-analysis-tool#198 · 2 comments ·
Maintainers usually reply within 1 day
-
Area/CLI Type/Improvement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ballerina-platform/static-code-analysis-tool#140 ·
Maintainers usually reply within 1 day
-
Area/Configuration Type/New Feature
Difficulty 3/5 1-2 days Newbie friendliness 52/100
ballerina-platform/static-code-analysis-tool#211 ·
Maintainers usually reply within 1 day
All issues in ballerina-platform/static-code-analysis-tool
Similar issues
-
triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
xerial/sqlite-jdbc#1515 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
eclipse-dirigible/dirigible#8636 · 1 comment ·
Maintainers usually reply within 1 day
-
bug severity-medium XS
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
nikolas-charalambidis/facepalm-maven-plugin#291 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
OakLoaf/PluginUpdater#264 ·
Maintainers usually reply within 1 day
-
[Bug]: withStartupTimeout() changes the startup timeout of all containers that use the default wait strategyPossibly taken @aymenjamaaoui claimed this today. Opentype/bug
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
testcontainers/testcontainers-java#12171 ·
Maintainers usually reply within 1 day