Add support to identify fields from which type-inclusion in record types #276
Add support to identify fields from which type-inclusion in record types #276dulajdilshan wants to merge 3 commits intoballerina-platform:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support to identify fields from which type inclusion they originate in record types. This helps track the source of inherited fields when record types include other types using the *TypeName syntax in Ballerina.
Key changes:
- Added
includedInfield to Member class to track type inclusion source - Modified TypeTransformer to map fields to their inclusion types
- Updated test data to reflect the new field information
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Member.java | Added includedIn parameter to Member record and MemberBuilder |
| TypeTransformer.java | Implemented logic to track field-to-inclusion mapping |
| types.bal | Added test cases for complex type inclusions |
| *.json | Updated test expectations with includedIn field values |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // Assume that type inclusion is always a type reference | ||
| TypeDefinitionSymbol typeDef = | ||
| (TypeDefinitionSymbol) ((TypeReferenceTypeSymbol) typeInclusion).definition(); |
There was a problem hiding this comment.
Unsafe cast operation without type checking. The code assumes typeInclusion is always a TypeReferenceTypeSymbol, but this should be verified before casting to prevent ClassCastException.
| int studentId; | ||
| decimal universityCode; |
There was a problem hiding this comment.
Field studentId in EngineeringStudent conflicts with the inherited field from Student. Field universityCode overrides the one from UndergraduateStudent with a different type (decimal vs float|decimal). This creates ambiguity and should be documented or reconsidered.
| int studentId; | |
| decimal universityCode; | |
| // studentId is inherited from Student; do not redeclare to avoid ambiguity | |
| float|decimal universityCode; |
| int|decimal id; | ||
| |}; |
There was a problem hiding this comment.
Field id in Rec2 has the same name and type as the inherited field from Rec1. This creates redundancy and potential confusion about field precedence.
| int|decimal id; | |
| |}; | |
| |}; |
Purpose
$title
Addresses wso2/product-ballerina-integrator#779