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] - Recursive Section Member Reference Isn't Accepted as Valid #340

Open
bgribaudo opened this issue Aug 12, 2022 · 4 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@bgribaudo
Copy link
Contributor

Expected behavior
The M language specification and the existing Power Query SDK allow a section member to use an exclusive identifier reference to refer to itself (e.g. the SumConsecutive(x - 1) reference in the below example).

section SomeSection;

SumConsecutive = (x) => if x <= 0 then 0 else x + SumConsecutive(x - 1);

Actual behavior
The parser considers the above-mentioned reference an error, complaining that it "cannot find the name 'SumConsecutive'".
image

To Reproduce
In VSCode, create a new Power Query document. Paste in the above M code. The error shown in the screenshot will then be displayed.

Additional context
Power Query / M Language extension version: v0.1.42

Thank you for your help with this, and for the VSCode extension!

@bgribaudo bgribaudo added the bug Something isn't working label Aug 12, 2022
@JordanBoltonMN
Copy link
Contributor

I don't believe this is a bug. Recursive functions should have the @ prefix, and if you add that prefix then the parser doesn't experience an error.

Thoughts?

@bgribaudo
Copy link
Contributor Author

Hi @JordanBoltonMN,

Thanks for taking a look at this!

Recursive functions should have the @ prefix[....]

I believe this is only true when the identifier being referenced is a record field or let expression variable.

From the language specification's discussion on Identifier references:

It is an error for an exclusive-identifier-reference to refer to an identifier that is currently being initialized if the referenced identifier is defined inside a record-initializer-expression or let-expression.

In this issue, the referenced identifier is a section member, so based on the above quote from the language specification (and as discussed in MicrosoftDocs/query-docs#9 (comment)), I believe an exclusive identifier reference (no @) should be considered valid in this case.

@JordanBoltonMN
Copy link
Contributor

I believe you're right in that it's not a requirement on section members. If I had to guess this was a bug in the C# parser that went unnoticed, but in any case it's been shipped for who knows how long so it's now a feature. I'll have to update the scope generation for section members to include both @name and name.

@bgribaudo
Copy link
Contributor Author

Thank you, @JordanBoltonMN!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants