Skip to content

split bitwise-assignment operators (&=, &.=, etc) don't return lvalues #22412

Closed
@mauke

Description

@mauke

Description
Assignment operators (like = itself, but also += or >>=) are supposed to return their left operand as an lvalue, which can then be further modified within the same expression. The old combined numeric/string bitwise assignment operators do this, but the new(er) split numeric and string bitwise operators (as provided by use feature qw(bitwise)) do not.

Steps to Reproduce

$ perl -wle '$_ = 1; ($_ |= 9) ^= 4; print'
13
$ perl -wle '$_ = "HI"; ($_ |= "") ^= " " x 2; print'
hi
$ perl -wle 'use feature qw(bitwise); $_ = 1; ($_ |= 9) ^= 4; print'
Can't modify numeric bitwise or (|) in numeric bitwise xor (^) at -e line 1, near "4;"
Execution of -e aborted due to compilation errors.
$ perl -wle 'use feature qw(bitwise); $_ = "HI"; ($_ |.= "") ^.= " " x 2; print'
Can't modify string bitwise or (|.) in string bitwise xor (^.) at -e line 1, near "2;"
Execution of -e aborted due to compilation errors.

Expected behavior

$ perl -wle '$_ = 1; ($_ |= 9) ^= 4; print'
13
$ perl -wle '$_ = "HI"; ($_ |= "") ^= " " x 2; print'
hi
$ perl -wle 'use feature qw(bitwise); $_ = 1; ($_ |= 9) ^= 4; print'
13
$ perl -wle 'use feature qw(bitwise); $_ = "HI"; ($_ |.= "") ^.= " " x 2; print'
hi

v5.40.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions