perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

feature 'class': I can't use a method with use overload

Open HaraldJoerg opened this issue 11 months ago • 1 comments

This is from bleadperl, compiled by myself: This is perl 5, version 39, subversion 9 (v5.39.9 (v5.39.4-687-gabac0992d7)) built for x86_64-linux

The following code fails to compile with the message Field $f is not accessible outside a method at N.pm line 5.

use feature 'class';
class N {
    field $f = 'stringified';
    use overload ( q("") => method { $f } );
}

Clearly $f is inside a method. The same construct works with Object::Pad, and according to LeoNerd in IRC is supposed to work with feature 'class'. He suggested I should file a bug.

A workaround (also suggested by LeoNerd) is to postpone the import part to runtime:

require overload; overload->import( q("") => method { $f } ) ;

HaraldJoerg avatar Mar 20 '24 16:03 HaraldJoerg

This is from bleadperl, compiled by myself: This is perl 5, version 39, subversion 9 (v5.39.9 (v5.39.4-687-gabac0992d7)) built for x86_64-linux

The following code fails to compile with the message Field $f is not accessible outside a method at N.pm line 5.

use feature 'class';
class N {
    field $f = 'stringified';
    use overload ( q("") => method { $f } );
}

Clearly $f is inside a method. The same construct works with Object::Pad, and according to LeoNerd in IRC is supposed to work with feature 'class'. He suggested I should file a bug.

A workaround (also suggested by LeoNerd) is to postpone the import part to runtime:

require overload; overload->import( q("") => method { $f } ) ;

@leonerd, could you take a look? Thanks.

jkeenan avatar Mar 20 '24 22:03 jkeenan