Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: semanticModel.references(symbol) gives invalid reference count for object method parameters. #43477

Open
SasinduDilshara opened this issue Oct 10, 2024 · 0 comments
Labels
Area/SemanticAPI Semantic API Related Issues #Compiler Team/CompilerFETools Semantic API, Formatter, Shell Type/Bug

Comments

@SasinduDilshara
Copy link
Contributor

Description

For the code mention in [1], When I am try to find the references of the objParam parameter inside the method in the module level object declaration using the semanticModel, it gives the result as 4. But the actual value should be 2.

[1] -

import ballerina/http;

type IncludedRecord record {int a;};

public function testExprFunctions(int a, int b, int c) { // warning * 2
   [1,2].forEach(element => ()); // warning
   [1,2].forEach(element => doNothing(element + c));
}

function (int, int) returns int anonFunc1 = (x, y) => x + y;

function (int, int) returns int anonFunc2 = function (int x, int y) returns int => x + y;

public function anonFunc4(int a) => [1,2].forEach(element => doNothing(element)); // warning

public function anonFunc3(int a) => [1,2].forEach(element => doNothing(a)); // warning

function (int, int) returns int anonFunc5 = (x, y) => x; // warning

function (int, int) returns int anonFunc6 = function (int x, int y) returns int => x; // warning

public function anonFunc7(int a, int b) => [1,2].forEach(element => doNothing(b)); // warning * 2

type F function (int, int) returns int;

type R record {
    F f = (a, b) => a; // BUG: https://github.com/ballerina-platform/ballerina-lang/issues/43474
    F antherF = function(int a, int b) returns int { // warning
        return b;
    };
};

public function testInlineFunctionDecl() {
    F[] arr = [
        (a, b) => a, // warning
        function(int a, int b) returns int { // warning
            return b;
        }
    ];
}

function test(int a, int b) returns int {
    return a + b;
}

function test2(int a, int b) returns int => a + b;

function test3(int a, int b, int c) returns int { // warning
    return a + b;
}

function test4(int a, int b, int c) returns int => a + b; // warning

function test5(int a, int b, int c, int d) returns int { // warning * 2
    return test(a, b);
}

function test6(int a, int b, int c, int d) returns int => test(a, b); // warning * 2

function test7(int a, int b, int c = 3) returns int {
    return a + b + c;
}

function test8(int a, int b, int c = 3) returns int { //warning
    return a + b;
}

function test9(int a, int b, int c = 3) returns int => a + b; // warning

function test10(int a, int b, int c = 3) returns int => c + test(a, b);

function test11(int a, int b, int... c) returns string => a.toString(); // warning * 2

function test12(int a, int b, int... c) returns string { // warning * 2
    return a.toString();
}

class A {
    function test(int a, int b) returns int {
        return a + b;
    }

    function test2(int a, int b) returns int => a + b;

    function test3(int a, int b, int c) returns int { // warning
        return a + b;
    }

    function test4(int a, int b, int c) returns int => a + b; // warning

    function test5(int a, int b, int c, int d) returns int { // warning * 2
        return test(a, b);
    }

    function test6(int a, int b, int c, int d) returns int => test(a, b); // warning * 2

    function test7(int a, int b, int c = 3) returns int {
        return a + b + c;
    }

    function test8(int a, int b, int c = 3) returns int { // warning
        return a + b;
    }

    function test9(int a, int b, int c = 3) returns int => a + b; // warning

    function test10(int a, int b, int c = 3) returns int => c + test(a, b);

    function test11(int a, int b, int... c) returns string => a.toString(); // warning * 2

    function test12(int a, int b, int... c) returns string { // warning * 2
        return a.toString();
    }

    function testIncludedParams(*IncludedRecord o) {// warning
        return;
    }

    function testIncludedParams2(*IncludedRecord o) {
        doNothing(o);
        return;
    }
}

service /a on new http:Listener(8080) {
    resource function get test(int a, int b) returns int {
        return a + b;
    }

    resource function get test2(int a, int b) returns int => a + b;

    resource function get test3(int a, int b, int c) returns int { // warning
        return a + b;
    }

    resource function post test4(int a, int b, int c) returns int => a + b; // warning

    resource function post test5(int a, int b, int c, int d) returns int { // warning * 2
        return test(a, b);
    }

    resource function post test6(int a, int b, int c, int d) returns int => test(a, b); // warning * 2

    resource function post test7(int a, int b, int c = 3) returns int {
        return a + b + c;
    }

    resource function post test8(int a, int b, int c = 3) returns int {  // warning
        return a + b;
    }

    resource function post test9(int a, int b, int c = 3) returns int => a + b; // warning

    resource function post test10(int a, int b, int c = 3) returns int => c + test(a, b);

    resource function post test11(int a, int b, int... c) returns string => a.toString(); // warning * 2

    resource function post test12(int a, int b, int... c) returns string { // warning * 2
        return a.toString();
    }

    function testIncludedParams(*IncludedRecord o) {// warning
        return;
    }

    function testIncludedParams2(*IncludedRecord o) {
        doNothing(o);
        return;
    }
}

object {} a = object {
    function test(int a, int b) returns int {
        return a + b;
    }

    function test2(int a, int b) returns int => a + b;

    function test3(int objParam, int b, int c) returns int { // warning
        return objParam + b;
    }

    remote function test4(int a, int b, int c) returns int => a + b; // warning

    remote function test5(int a, int b, int c, int d) returns int { // warning * 2
        return test(a, b);
    }

    function test6(int a, int b, int c, int d) returns int => test(a, b); // warning * 2

    function test7(int a, int b, int c = 3) returns int {
        return a + b + c;
    }

    function test8(int a, int b, int c = 3) returns int { // warning
        return a + b;
    }

    remote function test9(int a, int b, int c = 3) returns int => a + b; // warning

    function test10(int a, int b, int c = 3) returns int => c + test(a, b);

    function test11(int a, int b, int... c) returns string => a.toString(); // warning * 2

    function test12(int a, int b, int... c) returns string { // warning * 2
        return a.toString();
    }

    function testIncludedParams(*IncludedRecord o) {// warning
        return;
    }

    function testIncludedParams2(*IncludedRecord o) {
        doNothing(o);
        return;
    }
};

public function main(int a, int b, int c) { // warning
    _ = test(a, c);
    [1,2].forEach(element => ()); // warning
    [1,2].forEach(element => doNothing(element));
}

function doNothing(any a) { // warning
    return;
}

public function t(int a, int b, int c) { // warning * 2
    var fn = function(int a2, int b2) returns int => b; // warning * 2
    int _ = fn(1,2);
}

function testIncludedParams(*IncludedRecord includedparam) {// warning
    return;
}

function testIncludedParams2(*IncludedRecord includedparam) {
    doNothing(includedparam);
    return;
}

Steps to Reproduce

No response

Affected Version(s)

No response

OS, DB, other environment details and versions

No response

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@SasinduDilshara SasinduDilshara added Type/Bug Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Area/SemanticAPI Semantic API Related Issues #Compiler labels Oct 10, 2024
@MaryamZi MaryamZi added Team/CompilerFETools Semantic API, Formatter, Shell and removed Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. labels Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/SemanticAPI Semantic API Related Issues #Compiler Team/CompilerFETools Semantic API, Formatter, Shell Type/Bug
Projects
None yet
Development

No branches or pull requests

2 participants