vlang / ui

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

accessing map value that contain pointers requires an `or {}` block outside `unsafe` #567

Closed juan-db closed 4 months ago

juan-db commented 5 months ago

V full version: V 0.4.4 0910401.5a752c9 OS: macos, macOS, 14.2.1, 23C71 Processor: 11 cpus, 64bit, little endian, Apple M3 Pro

vexe mtime: 2024-01-27 17:06:33

Git version: git version 2.39.3 (Apple Git-145) Git vroot status: weekly.2024.03-85-g5a752c9a (1 commit(s) behind V master) .git/config present: true

CC version: Apple clang version 15.0.0 (clang-1500.1.0.2.5) thirdparty/tcc status: thirdparty-macos-arm64 a668e5a0

V UI: version 0.0.4

What did you do?

Ran v main.v from the command line.

// main.v
import ui

struct App {
mut:
    window     &ui.Window = unsafe { nil }
}

fn main() {
    mut app := &App{}
    app.window = ui.window(
        width: 600
        height: 400
        title: 'V UI Demo'
        children: [
            ui.row(
                margin: ui.Margin{10, 10, 10, 10}
                children: [
                    ui.column(
                        width: 200
                        spacing: 13
                        children: [
                            ui.label(
                                text: 'Hello'
                            ),
                        ]
                    ),
                ]
            ),
        ]
    )
    ui.run(app.window)
}

What did you expect to see? The file to compile without warnings / notices.

What did you see instead?

<vmodules dir>/ui/src/interface_action.v:34:23: notice: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
   32 | pub fn (s &Actionable) run_action(action string) {
   33 |     if action in s.actions {
   34 |         action_ := s.actions[action]
      |                             ~~~~~~~~
   35 |         action_.action_fn(action_.context)
   36 |     }
<vmodules dir>/ui/src/interface_shortcut.v:32:20: notice: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
   30 |     _, code, key := parse_shortcut(shortcut)
   31 |     if code == 0 {
   32 |         s.shortcuts.chars[key].context = context
      |                          ~~~~~
   33 |     } else {
   34 |         s.shortcuts.keys[code].context = context
<vmodules dir>/ui/src/interface_shortcut.v:34:19: notice: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
   32 |         s.shortcuts.chars[key].context = context
   33 |     } else {
   34 |         s.shortcuts.keys[code].context = context
      |                         ~~~~~~
   35 |     }
   36 | }
<vmodules dir>/ui/src/interface_shortcut.v:73:24: notice: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
   71 |     }
   72 |     if s in shortcuts.chars {
   73 |         sc := shortcuts.chars[s]
      |                              ~~~
   74 |         if has_key_mods(e.mods, sc.mods) {
   75 |             if sc.context != unsafe { nil } {
<vmodules dir>/ui/src/interface_shortcut.v:88:23: notice: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
   86 |     // println("key_shortcut ${int(e.key)}")
   87 |     if int(e.key) in shortcuts.keys {
   88 |         sc := shortcuts.keys[int(e.key)]
      |                             ~~~~~~~~~~~~
   89 |         if has_key_mods(e.mods, sc.mods) {
   90 |             if sc.context != unsafe { nil } {
<vmodules dir>/ui/src/picture.v:96:32: notice: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
   94 |         }
   95 |         if !pic.use_cache && pic.path in u.resource_cache {
   96 |             pic.image = u.resource_cache[pic.path]
      |                                         ~~~~~~~~~~
   97 |         } else if mut pic.ui.dd is DrawDeviceContext {
   98 |             mut dd := pic.ui.dd
<vmodules dir>/ui/src/ui.v:150:12: notice: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
  148 |         if img := gui.dd.create_image_from_byte_array(b) {
  149 |             gui.imgs[id] = img
  150 |             gui.imgs[id].path = path
      |                     ~~~~
  151 |         }
  152 |     }
<vmodules dir>/ui/src/ui.v:156:17: notice: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
  154 |
  155 | pub fn (gui &UI) img(id string) gg.Image {
  156 |     return gui.imgs[id]
      |                    ~~~~
  157 | }
  158 |
spytheman commented 4 months ago

After #570 , there are no more notices with latest V: image