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

Only a line number is printed when assigning to immutable values (stuff; $x = 42; stuff) #5376

Open
p6rt opened this issue Jun 14, 2016 · 7 comments
Labels
LTA

Comments

@p6rt
Copy link

@p6rt p6rt commented Jun 14, 2016

Migrated from rt.perl.org#128402 (status was 'open')

Searchable as RT128402$

@p6rt
Copy link
Author

@p6rt p6rt commented Jun 14, 2016

From @AlexDaniel

Code​:
my $x := 42;
my $a = 4 + 8; $x = 24; my $b = 15 + 16;

Result​:
Cannot assign to an immutable value
  in block <unit> at foo.p6 line 2

Line 2, right, but where exactly? Surely it can also print the cursor position or something.

@p6rt
Copy link
Author

@p6rt p6rt commented Jun 14, 2016

From @AlexDaniel

Right. After thinking about it, I now realize that almost any run-time error is giving such LTA error message.

Perhaps instead of storing just the line number it should store something else, maybe the global position in the file or something. So that it can give an error with up to semicolon precision, not just the line number.

Maybe the title of this bug report should be changed to something more general.

@p6rt
Copy link
Author

@p6rt p6rt commented Jun 15, 2016

From @lizmat

On 15 Jun 2016, at 00​:38, Alex Jakimenko (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Alex Jakimenko
# Please include the string​: [perl #​128402]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=128402 >

Code​:
my $x := 42;
my $a = 4 + 8; $x = 24; my $b = 15 + 16;

Result​:
Cannot assign to an immutable value
in block <unit> at foo.p6 line 2

Line 2, right, but where exactly? Surely it can also print the cursor position or something.

We don’t have the $/.CURSOR around at runtime. So in order to show where it happened in the line, one would have to also put that info in the opcodes. That feels like bloat to me.

Workaround​: put the assignments on different lines :-)

Liz

@p6rt
Copy link
Author

@p6rt p6rt commented Jun 15, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

@p6rt p6rt commented Jun 15, 2016

From 1parrota@gmail.com

I concur. The language shouldn't bend over backwards to accommodate bad habits.

On 6/15/16, Elizabeth Mattijsen <liz@​dijkmat.nl> wrote​:

On 15 Jun 2016, at 00​:38, Alex Jakimenko (via RT)
<perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Alex Jakimenko
# Please include the string​: [perl #​128402]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=128402 >

Code​:
my $x := 42;
my $a = 4 + 8; $x = 24; my $b = 15 + 16;

Result​:
Cannot assign to an immutable value
in block <unit> at foo.p6 line 2

Line 2, right, but where exactly? Surely it can also print the cursor
position or something.

We don’t have the $/.CURSOR around at runtime. So in order to show where it
happened in the line, one would have to also put that info in the opcodes.
That feels like bloat to me.

Workaround​: put the assignments on different lines :-)

Liz

@p6rt
Copy link
Author

@p6rt p6rt commented Jun 15, 2016

From @AlexDaniel

On Wed Jun 15 16​:24​:04 2016, 1parrota@​gmail.com wrote​:

I concur. The language shouldn't bend over backwards to accommodate
bad habits.

On 6/15/16, Elizabeth Mattijsen <liz@​dijkmat.nl> wrote​:

On 15 Jun 2016, at 00​:38, Alex Jakimenko (via RT)
<perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Alex Jakimenko
# Please include the string​: [perl #​128402]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=128402 >

Code​:
my $x := 42;
my $a = 4 + 8; $x = 24; my $b = 15 + 16;

Result​:
Cannot assign to an immutable value
in block <unit> at foo.p6 line 2

Line 2, right, but where exactly? Surely it can also print the
cursor
position or something.

We don’t have the $/.CURSOR around at runtime. So in order to show
where it
happened in the line, one would have to also put that info in the
opcodes.
That feels like bloat to me.

Workaround​: put the assignments on different lines :-)

Liz

Bad habits like what? Using a one liner in your command line? Or using camelia on IRC? Sure, you can avoid it, but it does not make the error message any more awesome.

As for the implementation, I don't know. It would be sad if there's no easy way to fix it. But at the same time I'm not sure why it is possible to hold the line number without any problems but having some additional information (maybe even stored in the same int) is such a big problem.

@p6rt
Copy link
Author

@p6rt p6rt commented Jul 9, 2016

From @niner

Well we would have to annotate MAST and JAST nodes with the column information in addition to the line number. The column is surprisingly easy to get by replacing​:
my $line := HLL​::Compiler.lineof($node.orig(), $node.from(), :cache(1));
with​:
my $line_col := HLL​::Compiler.line_and_column_of($node.orig(), $node.from(), :cache(1));
my $line := nqp​::atpos_i($line_col, 0);
my $column := nqp​::atpos_i($line_col, 1);

lineof actually calls line_and_column_of and just discards the column data.

So the cost is one annotate per node and a couple of minutes of coding time. Benchmarks would show if it's worth it. Or maybe jnthn can shoot it down even earlier by telling is that this would cost a lot ;)

@p6rt p6rt added the LTA label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.