On Fri, 08 Sep 2017 18:37:50 -0700, tomentiru...@gmail.com wrote:
> 
> > my @h
> []
> > @h.splice: 0, 0, 1.Seq
> []
> > @h[0].VAR.WHAT
> (Int)
> > @h[0] = 5
> Cannot modify an immutable Int (1)
>   in block <unit> at <unknown file> line 1
> 
> I got hit by this with: @a.splice: 0, 0, Any xx 2

Good find.

It's also not specific to `Seq` - it looks like it happens whenever the 
replacement elements are passed to `splice` as a nested structure rather than 
as flat arguments:

    my @h;
    @h.splice: 0, 0, 'a';
    @h.splice: 1, 0, ('b',);

    dd @h;                # Array @h = ["a", "b"]
    say @h[0].VAR.^name;  # Scalar
    say @h[1].VAR.^name;  # Str

Conceptually¹⁺², the `splice` routine takes the replacements as a `*@` slurpy, 
so whether they're passed in nested or flat form should not matter.

But Rakudo currently implements the routine with a `| is raw` signature:

    say Array.^find_method("splice").signature;  # (Mu $: | is raw)

...and apparently does the parameter flattening manually, in a way that 
introduces this bug.

Until it is fixed, a work-around is to flatten the replacement elements into 
the argument list of `splice` using `|`:

    @a.splice: 0, 0, |(Any xx 2);

---
[1] https://docs.perl6.org/routine/splice
[2] https://design.perl6.org/S32/Containers.html#splice

Reply via email to