Skip to content

Fixed Type casting error & Added ListView example#268

Merged
rockorager merged 4 commits intorockorager:mainfrom
vg006:main
Dec 23, 2025
Merged

Fixed Type casting error & Added ListView example#268
rockorager merged 4 commits intorockorager:mainfrom
vg006:main

Conversation

@vg006
Copy link
Contributor

@vg006 vg006 commented Nov 6, 2025

Problem:

TLDR:

  • Fixed type casting issue in TextView widget, by explicit type casting using @as function.
  • Added Nix flakes and configs to setup the development environment for libvaxis
  • I noticed this issue, when building my project with the TextView Widget that contains a line, that attempts to perform type coercion between error union types.

  • Actually the problem arises, when Zig compiler sees a return type of error!u3 from the std.unicode.utf8CodepointSequenceLength(), instead of error!usize

  • Zig allows type coercion between integer types like u3 to usize, but doesn't allow coercion between error unions of type error!u3 and error!usize. Even in the presence of the catch expression, it expects the payload of type error!usize.

Error Message:

❯ zig build
install
└─ install main
   └─ compile exe main Debug native 1 errors
/<USER_HOME_PATH>/.cache/zig/p/vaxis-0.5.1-BWNV_OAsCQA13jnKNnBh97YjTP4K4YwAT-pkH-RaHlMI/src/widgets/TextView.zig:88:82: error: expected type '@typeInfo(@typeInfo(@TypeOf(unicode.utf8CodepointSequenceLength)).@"fn".return_type.?).error_union.error_set!usize', found '@typeInfo(@typeInfo(@TypeOf(unicode.utf8CodepointSequenceLength)).@"fn".return_type.?).error_union.error_set!u3'
                grapheme_start = iter.i - std.unicode.utf8CodepointSequenceLength(result.cp) catch 1;
                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/<USER_HOME_PATH>/.cache/zig/p/vaxis-0.5.1-BWNV_OAsCQA13jnKNnBh97YjTP4K4YwAT-pkH-RaHlMI/src/widgets/TextView.zig:88:82: note: error union payload 'u3' cannot cast into error union payload 'usize'
referenced by:
    write: /<USER_HOME_PATH>/.cache/zig/p/vaxis-0.5.1-BWNV_OAsCQA13jnKNnBh97YjTP4K4YwAT-pkH-RaHlMI/src/widgets/TextView.zig:20:31
    write [inlined]: /nix/store/09yzmfr207ad618mcm5jdy344ih3nj8w-zig-0.15.2/lib/zig/std/Io.zig:342:27
    main: src/main.zig:33:21
    3 reference(s) hidden; use '-freference-trace=6' to see all references
error: the following command failed with 1 compilation errors:
/nix/store/09yzmfr207ad618mcm5jdy344ih3nj8w-zig-0.15.2/bin/zig build-exe -I/nix/store/zxsb4q47qhbqchf2xhwrrv357m1mg2z3-libgit2-1.9.1-dev/include -L/nix/store/v1rqcqjajvr1n7splqzgxw1ffp2c7fqq-libgit2-1.9.1-lib/lib -lgit2 -ODebug --dep giz --dep vaxis -Mroot=/<USER_HOME_PATH>/<PROJECT_DIR_PATH>/src/main.zig -Mgiz=/<USER_HOME_PATH>/<PROJECT_DIR_PATH>/src/table.zig -ODebug --dep zigimg --dep uucode -Mvaxis=/<USER_HOME_PATH>/.cache/zig/p/vaxis-0.5.1-BWNV_OAsCQA13jnKNnBh97YjTP4K4YwAT-pkH-RaHlMI/src/main.zig -ODebug --dep zigimg -Mzigimg=/<USER_HOME_PATH>/.cache/zig/p/zigimg-0.1.0-8_eo2vHnEwCIVW34Q14Ec-xUlzIoVg86-7FU2ypPtxms/zigimg.zig -ODebug --dep types.zig --dep config.zig --dep types.x.zig --dep tables --dep get.zig -Muucode=/<USER_HOME_PATH>/.cache/zig/p/uucode-0.1.0-ZZjBPj96QADXyt5sqwBJUnhaDYs_qBeeKijZvlRa0eqM/src/root.zig -ODebug --dep config.zig --dep get.zig -Mtypes.zig=/<USER_HOME_PATH>/.cache/zig/p/uucode-0.1.0-ZZjBPj96QADXyt5sqwBJUnhaDYs_qBeeKijZvlRa0eqM/src/types.zig -ODebug --dep types.zig -Mconfig.zig=/<USER_HOME_PATH>/.cache/zig/p/uucode-0.1.0-ZZjBPj96QADXyt5sqwBJUnhaDYs_qBeeKijZvlRa0eqM/src/config.zig -ODebug --dep config.x.zig -Mtypes.x.zig=/<USER_HOME_PATH>/.cache/zig/p/uucode-0.1.0-ZZjBPj96QADXyt5sqwBJUnhaDYs_qBeeKijZvlRa0eqM/src/x/types.x.zig -ODebug --dep types.zig --dep types.x.zig --dep config.zig --dep build_config -Mtables=.zig-cache/o/25e92e77a3862bb271c84448e440f19b/tables.zig -ODebug --dep types.zig --dep tables -Mget.zig=/<USER_HOME_PATH>/.cache/zig/p/uucode-0.1.0-ZZjBPj96QADXyt5sqwBJUnhaDYs_qBeeKijZvlRa0eqM/src/get.zig -ODebug --dep types.x.zig --dep types.zig --dep config.zig -Mconfig.x.zig=/<USER_HOME_PATH>/.cache/zig/p/uucode-0.1.0-ZZjBPj96QADXyt5sqwBJUnhaDYs_qBeeKijZvlRa0eqM/src/x/config.x.zig --dep types.zig --dep config.zig --dep types.x.zig --dep config.x.zig -Mbuild_config=.zig-cache/o/fd18b32249ff398bc4015853405e77cf/build_config2.zig -lc --cache-dir .zig-cache --global-cache-dir /<USER_HOME_PATH>/.cache/zig --name main --zig-lib-dir /nix/store/09yzmfr207ad618mcm5jdy344ih3nj8w-zig-0.15.2/lib/zig/ --listen=-

Build Summary: 3/6 steps succeeded; 1 failed
install transitive failure
└─ install main transitive failure
   └─ compile exe main Debug native 1 errors

error: the following build command failed with exit code 1:

Solution:

  • This problem can be resolved by explicit type casting from u3 to usize using the builtin @as() function.
  • In addition to this, I have added minimal Nix flake and config to setup the development environment for the libvaxis library.

@vg006 vg006 changed the title Fix: Type casting and Development setup configs Fixed Type casting error & Added ListView example Nov 6, 2025
Copy link
Owner

@rockorager rockorager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few files to remove that I don't want to have in the repo (direnv and nix stuff)

@vg006
Copy link
Contributor Author

vg006 commented Nov 13, 2025

Hey @rockorager, I have removed the files flake.nix, flake.lock and the .envrc files.

@vg006
Copy link
Contributor Author

vg006 commented Dec 16, 2025

Hello @rockorager,

  • I have updated the branch main to that of the mainstream, with the type casting fix.
  • I have also removed the files that you asked to remove. ref
  • In addition to this, the PR adds the example of ListView widget.

Waiting for your approval to merge these changes.

@rockorager
Copy link
Owner

Good to go, can you rebase on main and then I'll merge?

@vg006
Copy link
Contributor Author

vg006 commented Dec 19, 2025

Hello @rockorager
I have rebased main branch on mine, and now it is up to date with the upstream.
So can you review once and merge the PR?

@vg006
Copy link
Contributor Author

vg006 commented Dec 23, 2025

Hello @rockorager
The changes are up to date with the upstream.
Waiting for your approval to merge it.

@rockorager rockorager merged commit 11f53c7 into rockorager:main Dec 23, 2025
@rockorager
Copy link
Owner

Sorry about that, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants