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]: Getting non-accessible symbol error for error intersections with details #42806

Closed
TharmiganK opened this issue May 27, 2024 · 2 comments · Fixed by #42876 or #42925
Closed

[Bug]: Getting non-accessible symbol error for error intersections with details #42806

TharmiganK opened this issue May 27, 2024 · 2 comments · Fixed by #42876 or #42925
Assignees
Labels
Milestone

Comments

@TharmiganK
Copy link
Contributor

Description

I am getting the following error when I try to use error types from a external ballerina package. The error types are intersections with detail records:

ERROR [main.bal:(8:16,8:171)] attempt to refer to non-accessible symbol '$anonIntersectionErrorType$_2'
ERROR [main.bal:(10:16,10:170)] attempt to refer to non-accessible symbol '$anonIntersectionErrorType$_3'
error: compilation contains errors

Please note that this compiler errors are only shown at the very first build, after that the compilation is successful.

Steps to Reproduce

  1. Create a ballerina library package:
$ bal new -t lib status-code-errors
  1. Add the following errors.bal file to the package:
public type Detail record {
    int statusCode;
    map<string[]> headers;
    anydata body;
};

public type StatusCodeBindingErrorDetail record {
    *Detail;
    boolean fromDefaultStatusCodeMapping;
};

public type Error distinct error;

public type ClientError distinct Error;

public type ApplicationResponseError distinct (ClientError & error<Detail>);

public type ClientRequestError distinct (ApplicationResponseError & error<Detail>);

public type RemoteServerError distinct (ApplicationResponseError & error<Detail>);

public type StatusCodeResponseBindingError distinct ClientError & error<StatusCodeBindingErrorDetail>;

public type StatusCodeBindingClientRequestError distinct StatusCodeResponseBindingError & ClientRequestError;

public type StatusCodeBindingRemoteServerError distinct StatusCodeResponseBindingError & RemoteServerError;
  1. Pack and push it to Ballerina local central:
$ bal pack; bal push --repository=local
  1. Create a new Ballerina package:
$ bal new sample
  1. Add the following local dependency to Ballerina.toml:
[[dependency]]
org = "tharmigan" # Change the org to your org
name = "status_code_errors"
version = "0.1.0"
repository = "local"
  1. Replace the main.bal file content with the following:
// Replace the package organization with your organization
import tharmigan/status_code_errors as http;

isolated function createStatusCodeResponseBindingError(int statusCode, map<string[]> headers, anydata body = ()) returns http:StatusCodeResponseBindingError {
    string reasonPhrase = string `incompatible type found for the response with non-default status code: ${statusCode}`;
    if 100 <= statusCode && statusCode <= 399 {
        return error http:StatusCodeResponseBindingError(reasonPhrase, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = false);
    } else if 400 <= statusCode && statusCode <= 499 {
        return error http:StatusCodeBindingClientRequestError(reasonPhrase, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = false);
    } else {
        return error http:StatusCodeBindingRemoteServerError(reasonPhrase, statusCode = statusCode, headers = headers, body = body, fromDefaultStatusCodeMapping = false);
    }
}
  1. Run the build for the first time:
$ bal build

Compiling source
        tharmigan/sample:0.1.0
ERROR [main.bal:(8:16,8:171)] attempt to refer to non-accessible symbol '$anonIntersectionErrorType$_4'
ERROR [main.bal:(10:16,10:170)] attempt to refer to non-accessible symbol '$anonIntersectionErrorType$_5'
error: compilation contains errors
  1. Run the build for the second time:
$ bal build

Compiling source
        tharmigan/sample:0.1.0

Generating executable
        target/bin/sample.jar

Affected Version(s)

Ballerina SwanLake Update 9(2201.9.0)

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

@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels May 27, 2024
@TharmiganK TharmiganK added Priority/Blocker and removed needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels May 27, 2024
@dulajdilshan dulajdilshan self-assigned this May 27, 2024
@dulajdilshan dulajdilshan moved this to Planned for Sprint in Ballerina Team Main Board May 27, 2024
@dulajdilshan dulajdilshan moved this from Planned for Sprint to In Progress in Ballerina Team Main Board May 29, 2024
@dulajdilshan
Copy link
Contributor

We are not getting the error in the 2nd run of bal build because we get the error symbol accessible via the BIR correctly.

Copy link

github-actions bot commented Jul 1, 2024

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@dulajdilshan dulajdilshan added the Reason/Regression The issue has introduced a regression. label Jul 1, 2024
@dulajdilshan dulajdilshan reopened this Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment