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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.35%. Comparing base (6399eae) to head (3fb731e).
Report is 14 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #43355      +/-   ##
============================================
- Coverage     77.37%   77.35%   -0.02%     
+ Complexity    58593    58586       -7     
============================================
  Files          3460     3460              
  Lines        220095   220080      -15     
  Branches      28912    28907       -5     
============================================
- Hits         170295   170247      -48     
- Misses        40382    40417      +35     
+ Partials       9418     9416       -2     

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

@lochana-chathura lochana-chathura added the Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. label Sep 5, 2024
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

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
3 participants