Confused on changing values in a struct

This doesn’t compile… Why? And why does this raylib-zig example compile?

const std = @import("std");

pub fn main() anyerror!void {
    var player = .{ .x = 400, .y = 280, .width = 40, .height = 40 };
    player.x += 2;

    std.debug.print("{any}", .{player});
}

Error:

error: value stored in comptime field does not match the default value of the field
    player.x += 2;

Error that should be showing the types (this error I included for the struct output)

error: incompatible types: 'struct{comptime x: comptime_int = 70, comptime y: comptime_int = 35, comptime width: comptime_int = 20, comptime height: comptime_int = 20}' and 'comptime_int'
    player += 1;

comptime x: comptime_int = 70

Why did the compiler decide to implement comptime?
Does the double comptime mean anything? (comptime of the variable vs the integer itself)

I understand that, comptime is a way for the code to modify itself for optimizations & security, for example enabling or disabling code for different OSs but I don’t understand why it is changing the types of the struct values, especially because it is mutable.

Welcome to ziggit!!

I believe you have created an anonymous struct type. Which I think has been removed from the language (master branch).

You can fix your code by creating a type for player:

const Player = struct {
    x: u16,
    y: u16,
    width: u8,
    height: u8,
}
pub fn main() anyerror!void {
    var player: Player = .{ .x = 400, .y = 280, .width = 40, .height = 40 };
    player.x += 2;

    std.debug.print("{any}", .{player});
}


Because the raylib example explicitely states the type of the variable to be rl.Rectangle, which itself has explicitely defined integer types for its struct members. In your anonymous struct (as pointed out by @kj4tmp), there are no explicit types given, so the compiler chooses comptime_int.

Thank you!