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

Block runtime property refs in runtime functions, fix a stack overflow #2623

Merged
merged 7 commits into from
May 12, 2021

Conversation

shenglol
Copy link
Contributor

@shenglol shenglol commented May 11, 2021

Fixes #2547.
Fixes #2494.



this.deployTimeConstantScopeSyntax = currentDeployTimeConstantScopeSyntax;
}
Copy link
Contributor Author

@shenglol shenglol May 11, 2021

Choose a reason for hiding this comment

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

The visitor only flags runtime property references, which is not enough. We should also block the runtime function calls at any location that requires a deploy-time constant. I've created #2622 to track this.

However, as the visitor gets a bit head-scratching, I feel like we should do a refactoring first and split the code instead of keeping adding stuffs, which will make it even less readable.

To simplify this, I think we would need 3 visitors. The first one will collect all syntaxes that requires deploy-time constants. The second one visits all the collected syntaxes and flags runtime properties and function calls. The third one also visits the collected syntaxes, but it only checks indirect runtime references in variable declarations.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I think splitting into three much simpler visitors absolutely makes sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good! I'll start the refactoring once I'm done with other bug fixes.

"));

result.Should().HaveDiagnostics(new[] {
// TODO: change the first diagnostic once https://github.com/Azure/bicep/issues/2624 is fixed.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found a bug #2624 related to list* function validation while adding this test.

Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@shenglol shenglol changed the title Block runtime property references in runtime functions Block runtime property refs in runtime functions and fix a stack overflow May 12, 2021
@shenglol shenglol changed the title Block runtime property refs in runtime functions and fix a stack overflow Block runtime property refs in runtime functions, fix a stack overflow May 12, 2021
@shenglol shenglol merged commit 9d980cc into main May 12, 2021
@shenglol shenglol deleted the shenglol/runtime-function-check branch May 12, 2021 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants