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

Inline doc comment is a compiler error #11333

Merged
merged 4 commits into from
Oct 16, 2024

Conversation

Akirathan
Copy link
Member

@Akirathan Akirathan commented Oct 15, 2024

Pull Request Description

Fix NPE thrown when compiling source with inline documentation comments, like

main args =
    v = 42 ## meh
    v

Important Notes

  • Handled by the rust parser as syntax error
  • When translating the input from the rust parser, we treat it as an unexpected expression - added tests.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.
  • If meaningful changes were made to logic or tests affecting Enso Cloud integration in the libraries,
    or the Snowflake database integration, a run of the Extra Tests has been scheduled.
    • If applicable, it is suggested to paste a link to a successful run of the Extra Tests.

@Akirathan Akirathan added the CI: No changelog needed Do not require a changelog entry for this PR. label Oct 15, 2024
@Akirathan Akirathan self-assigned this Oct 15, 2024
@kazcw
Copy link
Contributor

kazcw commented Oct 15, 2024

This should be a syntax error, so I added some parser changes.

Copy link
Contributor

@Frizi Frizi left a comment

Choose a reason for hiding this comment

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

approving the JS test change

Copy link
Contributor

@farmaazon farmaazon left a comment

Choose a reason for hiding this comment

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

Reviewed the rust part. Nitpicks only, quite optional

@@ -89,6 +92,7 @@ impl<'s, Inner: TreeConsumer<'s>> CompoundTokens<'s, Inner> {
if let Some(tree) = self.compounding.take().and_then(|builder| builder.flush()) {
self.inner.push_tree(tree);
}
self.has_preceding_item = default();
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I'd prefer false, as more "readable"

Copy link
Contributor

Choose a reason for hiding this comment

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

false would be simpler, but IMO it's more important here to express that the field is reset to its initial state than to emphasize the value of that state. I'd reinitialize the whole struct here, if it weren't for performance.

@@ -260,18 +277,21 @@ impl<'s> CompoundTokenBuilder<'s> for TextLiteralBuilder<'s> {
}

fn flush(self) -> Option<Tree<'s>> {
let Self { open, newline, elements } = self;
let Self { open, newline, elements, has_preceding_item: _ } = self;
Copy link
Contributor

Choose a reason for hiding this comment

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

A shorter form would be

Suggested change
let Self { open, newline, elements, has_preceding_item: _ } = self;
let Self { open, newline, elements, .. } = self;

Unless you really want to have an error here when another field will be added.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fields that can correctly be ignored here are the exception.

Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

Test written and CI is green. Good!

@JaroslavTulach JaroslavTulach linked an issue Oct 16, 2024 that may be closed by this pull request
@kazcw kazcw merged commit fb82130 into develop Oct 16, 2024
41 checks passed
@kazcw kazcw deleted the wip/akirathan/11276-inline-comment-npe branch October 16, 2024 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A simple inline comment crashes compiler with NPE
6 participants