Skip to content

Const in V can be modified #14916

Description

@pbspbsingh
const should_not_change = Employee{ "Ohh" }

struct Employee {
mut:
    name string
}

fn main() {
    println(should_not_change)

    mut arr := []&Employee{} 
    arr << &should_not_change
    
    arr[0].name = "Bhak be"
    println(should_not_change)
}

Expected the compilation to fail, however compiled and ran output:

$ v run main.v
Employee{
    name: 'Ohh'
}
Employee{
    name: 'Bhak be'
}

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