Skip to content

v language shared array slice error! #26663

Description

@qq1060794917

Describe the bug

v language uses a shared array, the shared array slice operation, running code error.

// shared_array.v:
fn main() {
    shared a := ["a", "b"]

    a << ["c", "d"]
    println("a: ${ rlock{ a } }") //print: ["a","b","c","d"]

    a3 := rlock{ a[3] } //print: d
    println("a3: ${ rlock{ a3 } }")

    // The following two lines run an error:
    a_slice := rlock{ a[1..3] } //Slice gone wrong
    println("a[1..3]: ${ rlock{ a_slice } }") //expect: ["b", "c"]
}

Reproduction Steps

fn main() {
    shared a := ["a", "b"]

    a << ["c", "d"]
    println("a: ${ rlock{ a } }") //print: ["a","b","c","d"]

    a3 := rlock{ a[3] } //print: d
    println("a3: ${ rlock{ a3 } }")

    // The following two lines run an error:
    a_slice := rlock{ a[1..3] } //Slice gone wrong
    println("a[1..3]: ${ rlock{ a_slice } }") //expect: ["b", "c"]
}

Expected Behavior

Normal should be able to take the slice and output the correct result. For example, this example should output correctly:
a[1..3]: ["b", "c"]

Current Behavior

The run error message is as follows:

~ $ v run shared_array.v
================== C compilation error (from cc): ==============
cc: /data/data/com.termux/files/usr/tmp/v_10264/shared_array.01KJEX8FMH7VYB2SPMPKQHDZD0.tmp.c:8820:7: error: assigning to '__shared__Array_string' (aka 'struct __shared__Array_string') from incompatible type 'array' (aka 'struct array')
cc:  8820 |                 _t5 = builtin__array_slice((*a).val, 1, 3);
cc:       |                     ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc: /data/data/com.termux/files/usr/tmp/v_10264/shared_array.01KJEX8FMH7VYB2SPMPKQHDZD0.tmp.c:8824:29: error: member reference type '__shared__Array_string' (aka 'struct __shared__Array_string') is not a pointer; did you mean to use '.'?
cc:  8824 |                 Array_string a_slice = _t5->val;
cc:       |                                        ~~~^~
cc:       |                                           .
cc: 2 errors generated.
================================================================
Try passing `-g` when compiling, to see a .v file:line information, that correlates more with the C error.
(Alternatively, pass `-show-c-output`, to print the full C error message).
builder error:
==================

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.5.0 57e617a

Environment details (OS name and version, etc.)

|V full version      |V 0.5.0 a8b0e1d5ed3096edce359cd5d7d2fbb7ab50d31e.57e617a
|:-------------------|:-------------------
|OS                  |termux, 5.10.136-android12-9-00020-gc9f59ef34367-ab9585114, #1 SMP PREEMPT Wed Feb 8 23:50:57 UTC 2023
|Processor           |8 cpus, 64bit, little endian
|Memory              |N/A
|                    |
|V executable        |/data/data/com.termux/files/home/v/v
|V last modified time|2026-02-27 07:02:36
|                    |
|V home dir          |OK, value: /data/data/com.termux/files/home/v
|VMODULES            |OK, value: /data/data/com.termux/files/home/.vmodules
|VTMP                |OK, value: /data/data/com.termux/files/usr/tmp/v_10264
|Current working dir |OK, value: /data/data/com.termux/files/home
|                    |
|Git version         |git version 2.51.0
|V git status        |57e617aa-dirty
|.git/config present |true
|                    |
|cc version          |clang version 20.1.8
|gcc version         |clang version 20.1.8
|clang version       |Android (dev, +pgo, -bolt, +lto, -mlgo, based on r522817b) clang version 18.0.2 (https://android.googlesource.com/toolchain/llvm-project d8003a456d14a3deb8054cdaa529ffbf02d9b262)
|tcc version         |N/A
|tcc git status      |thirdparty-unknown-unknown de82a130
|emcc version        |N/A
|glibc version       |readelf: Error: 'readlink (GNU coreutils) 9.7

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions