Skip to content

Conversation

@insomnimus
Copy link
Contributor

If a code passed to ?eval contains trailing single-line comments, the matching } in the code is commented out.

For example:

?eval `2 + 2 // returns 4`

Will not work as expected.

I've added a single newline(\n) in playground.rs Where the expression is wrapped in a block to print out
so the } is not commented out.

@technetos
Copy link
Owner

technetos commented Nov 15, 2021

Thanks for bringing this to our attention!!

The problem boils down to the following

The generated code is this:

fn main(){ println!("{:?}",{ 2 + 2 // returns 4 }); }

By adding the \n after the end of the user provided expression it transforms the expression posted to play.rlo into:

fn main(){ println!("{:?}",{ 2 + 2 // returns 4
}); }

effectively moving the remaining closing braces to the next line, preventing them from being commented out.

Instead of just breaking up the end, could we break up the whole expression into separate lines?

fn main(){
println!("{:?}",{
2 + 2 // returns 4
}); }

@tinaun Do you have any thoughts about this?

@khionu
Copy link
Contributor

khionu commented Nov 15, 2021

The difference between a single new line and "more" formatting is how it looks in the Gist, should we share one with the user. So, it's inconsequential, atm.

@technetos technetos merged commit c6c6cd6 into technetos:master Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants