vlang / ui

A cross-platform UI library written in V
MIT License
2.31k stars 154 forks source link

Error when building with autofree - ` ';' expected (got "_t2")` #510

Open ArtemkaKun opened 1 year ago

ArtemkaKun commented 1 year ago

V doctor

OS: linux, "Garuda Linux"
Processor: 16 cpus, 64bit, little endian, AMD Ryzen 7 3800X 8-Core Processor
CC version: cc (GCC) 12.2.1 20230201

getwd: /home/yuart
vmodules: /home/yuart/.vmodules
vroot: /home/yuart/Projects/v
vexe: /home/yuart/Projects/v/v
vexe mtime: 2023-03-01 21:46:21
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.3 d971d93.e2daa84

Git version: git version 2.39.2
Git vroot status: weekly.2023.08-45-ge2daa84a
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

UI package version

cdf521649d41ab93fc645f0a398d94fecb587883

System DE

DE: KDE Plasma 5.27.2
WM: KWin (Wayland)

What did you do?

Run the following code with v -autofree run .

import ui

[heap]
struct App {
mut:
    window ui.Window
    label  ui.Label
    model  Model
}

struct Model {
    counter_value int
}

enum Message {
    increment
    decrement
}

fn main() {
    mut app := App{}
    setup_app(mut app)

    ui.run(app.window)
}

fn setup_app(mut app App) {
    app.window = ui.window(
        width: 400
        height: 400
        title: 'MVU counter'
        children: [
            ui.column(
                margin: ui.Margin{50, 50, 50, 50}
                spacing: 5
                children: [
                    app.label,
                    ui.row(
                        spacing: 5
                        children: [
                            ui.button(
                                text: 'Increment'
                                width: 100
                                height: 50
                                text_size: 20
                                on_click: app.send_increment_signal
                            ),
                            ui.button(
                                text: 'Decrement'
                                width: 100
                                height: 50
                                text_size: 20
                                on_click: app.send_decrement_signal
                            ),
                        ]
                    ),
                ]
            ),
        ]
    )

    app.label = ui.label(text: '0', text_size: 36)
}

fn (mut app App) send_increment_signal(_ &ui.Button) {
    app.model = update(Message.increment, app.model)
    app.react_on_model_change()
}

fn (mut app App) send_decrement_signal(_ &ui.Button) {
    app.model = update(Message.decrement, app.model)
    app.react_on_model_change()
}

fn update(message Message, current_model Model) Model {
    return match message {
        .increment {
            Model{
                counter_value: current_model.counter_value + 1
            }
        }
        .decrement {
            Model{
                counter_value: current_model.counter_value - 1
            }
        }
    }
}

fn (mut app App) react_on_model_change() {
    app.label.text = app.model.counter_value.str()
}

What did you expect to see?

The program started as expected and a window appeared.

What did you see instead

The following error

==================
/tmp/v_1000/ui_counter.17501532973111399599.tmp.c:45264: warning: assignment discards qualifiers from pointer target type
/tmp/v_1000/ui_counter.17501532973111399599.tmp.c:67549: error: ';' expected (got "_t2")
...
==================
(Use `v -cg` to print the entire error message)

builder error:
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang