ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.82k stars 2.55k forks source link

Compiler bug . comptime variable object modifying members #9434

Open SrMordred opened 3 years ago

SrMordred commented 3 years ago

windows-x64 zig version 0.9.0-dev.476+3e67ef5c9

const T = struct {
    v: i32,

    pub fn f1(self: *@This()) void {
        self.v += 1;
    }
};

pub fn main() anyerror!void {
    comptime var r = T{ .v = 0 };

    _ = r.f1(); 

calling f1: Segmentation fault at address 0x7ff60c010cd8 D:\programming\zig\tests\src\main.zig:148:16: 0x7ff60bfeef0b in T::T.f1 (tests.obj) self.v += 1;

RetroDev256 commented 2 months ago

Well it is a compiler bug, but not a segfault. The bug is that it didn't prevent this from being compiled.