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]: RecordTypeSymbol.fieldDescriptors() returns NPE #42094

Closed
TharmiganK opened this issue Feb 1, 2024 · 5 comments · Fixed by #42108
Closed

[Bug]: RecordTypeSymbol.fieldDescriptors() returns NPE #42094

TharmiganK opened this issue Feb 1, 2024 · 5 comments · Fixed by #42108
Assignees
Labels
Area/Compiler Priority/Blocker Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation
Milestone

Comments

@TharmiganK
Copy link
Contributor

TharmiganK commented Feb 1, 2024

Description

I have an error intersection like this:

type ErrorDetail record {
    string|string[] headers?;
    anydata body?;
};
type StatusCodeError distinct error<ErrorDetail>;
type NotFoundError distinct StatusCodeError;

type UserErrorInfo record {|
    string timeStamp;
    string userId;
    string message;
|};

type UserErrorDetail record {|
    *ErrorDetail;
    UserErrorInfo body;
|};

type Error distinct error;

type UserNotFoundError Error & NotFoundError & error<UserErrorDetail>;

In the compiler plugin, I am accessing this UserNotFoundError type symbol and get the effective error type from the intersection. Then I get the type descriptor of the detail field which is a Ballerina Record Type in this case.

When I call fieldDescriptors() method on this Record Type I am getting a Null Pointer Error.

Screenshot 2024-02-01 at 18 30 14

Please note that this a blocker to this feature which is expected to deliver with update 9:

Steps to Reproduce

See the description above.

Java code:

TypeSymbol intersectionErrorType = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor();
TypeSymbol effectiveErrorType = ((IntersectionTypeSymbol) intersectionErrorType).effectiveTypeDescriptor();
TypeSymbol detailRecordType = ((ErrorTypeSymbol) effectiveErrorType).detailTypeDescriptor();
((RecordTypeSymbol) detailRecordType).fieldDescriptors();

Note:
If I change the error intersection like this then it works:

type Error0 distinct error<UserErrorDetail>;

type UserNotFoundError0 Error0 & NotFoundError;

Affected Version(s)

Ballerina SwanLake Update 8 (2201.8.4)

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 Feb 1, 2024
@nipunayf nipunayf added Area/Compiler Priority/Blocker Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. and removed needTriage The issue has to be inspected and labeled manually labels Feb 1, 2024
@nipunayf nipunayf self-assigned this Feb 1, 2024
@prakanth97
Copy link
Contributor

prakanth97 commented Feb 1, 2024

In the type resolver, UserNotFoundError is resolved properly, seems semantic api is not exposing it in BallerinaRecordTypeSymbol

@nipunayf
Copy link
Contributor

nipunayf commented Feb 1, 2024

The latest changes in the master appear to work properly for the above scenario, even using the semantic API.

image

@TharmiganK
Copy link
Contributor Author

@nipunayf please note that the sample is updated. The previous one was not reproducing this issue

@nipunayf
Copy link
Contributor

nipunayf commented Feb 2, 2024

The problem can be reduced to the following example.

type ErrorDetail record {
    string msg;
};

type UserNotFoundError distinct error & error<ErrorDetail> & error<ErrorDetail> ;

The error Cannot invoke "io.ballerina.tools.diagnostics.Location.lineRange()" because "symbol.pos" is null is generated at

After the first intersection between distinct error & error<ErrorDetail>, it generates a resultant record type, and the position of the msg field symbol is null, and this is propagated to the final intersection.

Copy link

github-actions bot commented Feb 8, 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.

@KavinduZoysa KavinduZoysa added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Feb 8, 2024
@nipunayf nipunayf added this to the 2201.9.0 milestone Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Compiler Priority/Blocker Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants