-
Notifications
You must be signed in to change notification settings - Fork 561
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
Recognise a :reader attribute on class fields #21927
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look good to me (but I'm no expert on OPcodes)
The opcode stuff was mostly copy-pasted from Object::Pad's implementation anyway ;) |
If @tonycoz has a moment I'd appreciate a look at the various UTF-8 handling around the padnames in particular. |
On a casual commandline test using Espernato (and therefore non-Latin1 Unicode), it appears to work for me:
|
pod/perlclass.pod
Outdated
(minus the leading sigil), but a different name can be specified in the | ||
attribute. The generated method will have an empty (i.e. zero-argument) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but a different name can be specified in the attribute
How? If by :reader(NAME)
let's document that too please (or give example thereof).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example added to docs.
It looks good to me, but I think it should have some UTF-8 name tests. |
t/class/accessor.t
Outdated
field $f :reader(get_f) = "value"; | ||
} | ||
|
||
is(Test2->new->get_f, "value", 'accessor with altered name'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should Test2->new->f
also work here? The POD suggests not but doesn't state it explicitly and there's no test confirming it doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test added
t/class/accessor.t
Outdated
|
||
# Alternative names | ||
{ | ||
class Test2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not that I expect it to be an issue here, but perhaps Test2 isn't the most unique class name? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair. I'll rename these to Testcase1
etc, and also fix up the names in the other .t
files in a separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this directly in 4650b6a
928c13f
to
2d845b3
Compare
@tonycoz Yes certainly, though I have a whole bunch I plan to steal from https://metacpan.org/release/PEVANS/Object-Pad-0.808/source/t/95utf8.t which test all of the class stuff. I'll do that in a separate test-only PR. (At least, I hope it'll be test-only. Maybe it will uncover a bug :) ) |
This causes a segfault, is this known:
Looks like we get a null or freed sv in (Likewise, this crashes in a different way - attempting to eat all memory or ... some other bug?
It can also crash like this:
Also, what happens in this case?
I guess we create a method call Also if you do |
2d845b3
to
2de9f54
Compare
Hrm; I don't seem to be able to reproduce that:
Surprising perhaps, yes. Similar would already happen with
That feels like a comment to make in documentation - "you can do this but you very likely should not." |
Ah but wait a moment, maybe something more subtle going on:
|
Turns out to have been a good ol' uninitialised pointer. Fixed by 4b75b72 |
Accepting that there should be a (warning? error?) when attempting to create a |
4b75b72
to
dd95f60
Compare
This came up in discussion for Perl#21927
This came up in discussion for #21927
Generates simple reader accessors.
Not yet addressed - any kind of writer or mutator.
perldelta to be written in a separate commit