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

Fix compiler crash with nested queries in select as a field #43355

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

poorna2152
Copy link
Contributor

@poorna2152 poorna2152 commented Sep 4, 2024

Purpose

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

Fixes #43336

Approach

The identifiers map in the QueryDesugar stores a set of identifiers and their symbols found in the lambda function created for clauses inside the query. When an identifier in a select clause is first used in a nested query or within a lambda function in a query, the symbol of that identifier is marked as a closure symbol. For consequent usages of this identifier in the select clause this symbol that has been marked as a closure should be used (i.e. for other fields in the select clause).

record {|string name; string[] courses;|}[] studentCourses = from Student student in students
        select {
            courses: from Grade grade in student.grades
                select grade.course,
            name: student.name
        };

Consider the above code. The student identifier inside the select clause is marked as a closure variable first because it is used within a nested query as in the first field. The second field also uses this student identifier and the variable of this second usage should also refer to the Symbol that is marked as a closure because of that nested field.

The current implementation restricts to using symbols of the identifiers from this identifiers map when either on in a nestedQuery or within an arrow function. This fix removes that check usage.

Samples

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

Remarks

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • 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

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.50%. Comparing base (c61fc38) to head (e3b2594).
Report is 115 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #43355      +/-   ##
============================================
- Coverage     77.50%   77.50%   -0.01%     
+ Complexity    58596    58593       -3     
============================================
  Files          3438     3438              
  Lines        219259   219259              
  Branches      28924    28924              
============================================
- Hits         169938   169926      -12     
- Misses        39902    39914      +12     
  Partials       9419     9419              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@heshanpadmasiri heshanpadmasiri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@poorna2152 poorna2152 marked this pull request as draft October 3, 2024 11:28
@poorna2152 poorna2152 changed the title Fix compiler crash with nested queries in select as a field [DO NOT MERGE] Fix compiler crash with nested queries in select as a field Oct 4, 2024
@poorna2152 poorna2152 changed the title [DO NOT MERGE] Fix compiler crash with nested queries in select as a field Fix compiler crash with nested queries in select as a field Oct 7, 2024
@poorna2152 poorna2152 marked this pull request as ready for review October 7, 2024 09:40
@gimantha gimantha merged commit 037c730 into ballerina-platform:master Oct 9, 2024
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Compiler crash with nested query expression containing another non nested field
4 participants