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 for setting ro attribute inside a trait_mod:<is> sub is [LTA] #4973

Open
p6rt opened this issue Dec 31, 2015 · 2 comments
Open

Comments

@p6rt
Copy link

p6rt commented Dec 31, 2015

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

Searchable as RT127110$

@p6rt
Copy link
Author

p6rt commented Dec 31, 2015

From @autarch

Given this code​:


use v6;

my role R {
  has $.thing;
}

multi sub trait_mod​:<is> (Attribute​:D $attr, :$whatever) {
  $attr does R;
  $attr.thing = 42;
}

class C {
  has $.val is whatever;
}


I get this error​:


===SORRY!=== Error while compiling /home/autarch/projects/perl6/MetaX-Attribute-LazyBuild/./foo
Cannot modify an immutable Any
at /home/autarch/projects/perl6/MetaX-Attribute-LazyBuild/./foo​:13


There are two problems here. One is that the line number is unhelpfully pointing at the line where I declare "has $.val is whatever" and the second is that I'm not being told what exact "immutable Any" can't be modified.

It'd be greatly preferable to get an error like "Cannot set immutable attribute thing on $attr at ...foo​:9"

@p6rt
Copy link
Author

p6rt commented Dec 31, 2015

From @autarch

mst++ pointed out that if the problem is with the _user_ of a trait, then reporting the error at the line where the trait is used does make sense. This argues for reporting both lines and/or just including a full call stack.

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