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

Crash when code to highlight includes a completely blank line #19

Open
raiph opened this issue Apr 23, 2014 · 1 comment
Open

Crash when code to highlight includes a completely blank line #19

raiph opened this issue Apr 23, 2014 · 1 comment

Comments

@raiph
Copy link
Contributor

raiph commented Apr 23, 2014

http://irclog.perlgeek.de/perl6/2014-04-23#i_8625892

Using Rakudo/MoarVM and debugger built a couple days ago.

@raiph raiph changed the title Crash if single step onto a line that might continue (no ; at the end) which is followed by a completely blank line Crash when I single step onto a line of code that might continue (eg say 1 vs `say 1;' ) which is followed by a completely blank line Apr 23, 2014
@raiph
Copy link
Contributor Author

raiph commented Apr 24, 2014

The bug was in the highlighted_lines sub which starts:

sub highlighted_lines(@lines, $start_line_pos, $end_line_pos) {
    @lines.map: {
        state $line = 0;
        NEXT $line++;
        my $safe_start_pos = [min] $start_line_pos, .chars - 1;
        my $safe_end_pos   = [min] $end_line_pos, .chars - 1;

.chars - 1 is -1 on zero length lines. So the $safe_*_pos variables ironically weren't safe.

Also, the NEXT had no effect in my tests.

The sub as it stands had highlighting oddities that seem to be due to the NEXT issue.

The sub also seemed unnecessarily complex, to the degree I found it difficult to reason about. I rewrote it to the following version which seems to more directly express what the sub has to do and which has been working in my testing:

sub highlighted_lines(@lines, $start_line_pos, $end_line_pos) {
    @lines.map: {
        state $line = 0;
        my $start_pos = ($line == 0)
                               ?? [min] $start_line_pos, .chars
                               !! 0;
        my $end_pos   = ($line == @lines.end)
                               ?? [min] $end_line_pos, .chars
                               !! .chars;
        my $rendered = colored('| ', 'blue');
        if $line == 0 {
            $rendered ~= .substr(0, $start_pos);
        }
        $rendered ~= colored(.substr($start_pos, $end_pos - $start_pos), 'bold yellow');
        if $line == @lines.end {
            $rendered ~= .substr($end_pos, .chars - $end_pos);
        }
        $line++;
        $rendered.subst("\r", "")
    }
}

@raiph raiph changed the title Crash when I single step onto a line of code that might continue (eg say 1 vs `say 1;' ) which is followed by a completely blank line Crash when code to highlight includes a completely blank line Apr 24, 2014
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

No branches or pull requests

1 participant