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

error message when you try to modify an ro parameter #4374

Open
p6rt opened this issue Jul 10, 2015 · 2 comments
Open

error message when you try to modify an ro parameter #4374

p6rt opened this issue Jul 10, 2015 · 2 comments
Labels
LTA Less Than Awesome; typically an error message that could be better

Comments

@p6rt
Copy link

p6rt commented Jul 10, 2015

Migrated from rt.perl.org#125590 (status was 'new')

Searchable as RT125590$

@p6rt
Copy link
Author

p6rt commented Jul 10, 2015

From @hoelzro

Simliar to https://rt-archive.perl.org/perl6/Ticket/Display.html?id=125531, but that ticket appears for more subtle reasons ($/ being modified as the result of operations like ~~).

If I try to modify an ro parameter, or the parameter to a for loop (which, when using ->, I guess is another sort of ro parameter), I get one of the two error messages​:

  sub foo(Str $str) {
  $str ~= 'another'; # Cannot assign to an immutable value
  $str .= substr(0, 3); # Cannot modify an immutable Str
  }

I've also seen "Cannot assign to a readonly variable or a value".

While the error message makes sense, it may be nice to...

  - Indicate the variable being assigned to, if it is indeed a variable.
  - (In the case of the linked ticket mentioning $/) Indicate the operation responsible for the writing
  - (Other than for $/) Suggest is copy or <-> if that is what the user means.

@p6rt
Copy link
Author

p6rt commented Jul 10, 2015

From @hoelzro

On 2015-07-10 05​:46​:10, rob@​hoelz.ro wrote​:

Simliar to https://rt-archive.perl.org/perl6/Ticket/Display.html?id=125531, but that
ticket appears for more subtle reasons ($/ being modified as the
result of operations like ~~).

If I try to modify an ro parameter, or the parameter to a for loop
(which, when using ->, I guess is another sort of ro parameter), I get
one of the two error messages​:

sub foo(Str $str) {
$str ~= 'another'; # Cannot assign to an immutable value
$str .= substr(0, 3); # Cannot modify an immutable Str
}

I've also seen "Cannot assign to a readonly variable or a value".

While the error message makes sense, it may be nice to...

- Indicate the variable being assigned to, if it is indeed a variable.
- (In the case of the linked ticket mentioning $/) Indicate the
operation responsible for the writing
- (Other than for $/) Suggest is copy or <-> if that is what the user
means.

"Cannot assign to a readonly variable or a value" occurs with for loop parameters.

@p6rt p6rt added the LTA Less Than Awesome; typically an error message that could be better label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTA Less Than Awesome; typically an error message that could be better
Projects
None yet
Development

No branches or pull requests

1 participant