ballerina-lang icon indicating copy to clipboard operation
ballerina-lang copied to clipboard

Fix `BIRPackage.importModules` containing duplicate elements

Open Thushara-Piyasekara opened this issue 11 months ago • 1 comments

Purpose

Describe the problems, issues, or needs driving this feature/fix and include links to related issues.

Fixes https://github.com/ballerina-platform/ballerina-lang/issues/42343

Approach

Restricted the addition of duplicate elements by the usage of a HashSet instead of an ArrayList and setting up the necessary equals() and hashCode() functions for the BIRImportModule class. This will filter the duplicate imports after the BIR Gen phase.

Samples

Provide high-level details about the samples related to this feature.

Remarks

The root cause of the duplicate imports is in the AST level. The duplicate imports originally derive from the import statements in .bal files. Since a ballerina project can have more than one .bal file it produces more than one BLangImportPackage.

image

These AST level imports are used by the DataflowAnalyzer to detect unused imports. Therefore duplicates are needed in AST level.

Due to above reasoning, the safe choice is to omit them during the BIR Gen phase.

Check List

  • [x] Read the Contributing Guide
  • [ ] Updated Change Log
  • [ ] Checked Tooling Support (#<Issue Number>)
  • [ ] Added necessary tests
    • [ ] Unit Tests
    • [ ] Spec Conformance Tests
    • [ ] Integration Tests
    • [ ] Ballerina By Example Tests
  • [ ] Increased Test Coverage
  • [ ] Added necessary documentation
    • [ ] API documentation
    • [ ] Module documentation in Module.md files
    • [ ] Ballerina By Examples

Thushara-Piyasekara avatar Mar 19 '24 09:03 Thushara-Piyasekara