diff --git a/examples/gg/mandelbrot.v b/examples/gg/mandelbrot.v index aa2619f09e..c5a639b92a 100644 --- a/examples/gg/mandelbrot.v +++ b/examples/gg/mandelbrot.v @@ -124,7 +124,7 @@ fn (mut state AppState) worker(id int, input chan MandelChunk, ready chan bool) fn (mut state AppState) draw() { mut istream_image := state.gg.get_cached_image_by_idx(state.iidx) - istream_image.update_pixel_data(state.pixels) + istream_image.update_pixel_data(unsafe { &u8(state.pixels) }) size := gg.window_size() state.gg.draw_image(0, 0, size.width, size.height, istream_image) } diff --git a/examples/gg/random.v b/examples/gg/random.v index 2de6c32e92..f54d82c2ee 100644 --- a/examples/gg/random.v +++ b/examples/gg/random.v @@ -30,7 +30,7 @@ fn (mut state AppState) update() { fn (mut state AppState) draw() { mut istream_image := state.gg.get_cached_image_by_idx(state.istream_idx) - istream_image.update_pixel_data(&state.pixels) + istream_image.update_pixel_data(unsafe { &u8(&state.pixels) }) size := gg.window_size() state.gg.draw_image(0, 0, size.width, size.height, istream_image) } diff --git a/examples/pendulum-simulation/modules/sim/anim/app.v b/examples/pendulum-simulation/modules/sim/anim/app.v index 4262c86870..429d0f9d14 100644 --- a/examples/pendulum-simulation/modules/sim/anim/app.v +++ b/examples/pendulum-simulation/modules/sim/anim/app.v @@ -59,6 +59,6 @@ fn frame(mut app App) { fn (mut app App) draw() { mut istream_image := app.gg.get_cached_image_by_idx(app.iidx) - istream_image.update_pixel_data(&app.pixels[0]) + istream_image.update_pixel_data(unsafe { &u8(&app.pixels[0]) }) app.gg.draw_image(0, 0, app.args.grid.width, app.args.grid.height, istream_image) } diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index e9b99b0a98..1f3239e597 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -224,6 +224,15 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan && got == ast.int_type_idx { return } + } else { + exp_sym_idx := c.table.sym(expected).idx + got_sym_idx := c.table.sym(got).idx + if expected.is_ptr() && got.is_ptr() && exp_sym_idx != got_sym_idx + && exp_sym_idx in [ast.u8_type_idx, ast.byteptr_type_idx] + && got_sym_idx !in [ast.u8_type_idx, ast.byteptr_type_idx] { + got_typ_str, expected_typ_str := c.get_string_names_of(got, expected) + return error('cannot use `${got_typ_str}` as `${expected_typ_str}`') + } } // check int signed/unsigned mismatch if got == ast.int_literal_type_idx && expected in ast.unsigned_integer_type_idxs diff --git a/vlib/v/checker/tests/fn_call_ref_incompatible_u8_test.out b/vlib/v/checker/tests/fn_call_ref_incompatible_u8_test.out new file mode 100644 index 0000000000..46130eaf6c --- /dev/null +++ b/vlib/v/checker/tests/fn_call_ref_incompatible_u8_test.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/fn_call_ref_incompatible_u8_test.vv:9:28: error: cannot use `&[]int` as `&u8` in argument 1 to `accept_only_u8_references` + 7 | fn test_main() { + 8 | a := [1, 2, 3] + 9 | accept_only_u8_references(&a) + | ~~ + 10 | } diff --git a/vlib/v/checker/tests/fn_call_ref_incompatible_u8_test.vv b/vlib/v/checker/tests/fn_call_ref_incompatible_u8_test.vv new file mode 100644 index 0000000000..af5ff8cbaf --- /dev/null +++ b/vlib/v/checker/tests/fn_call_ref_incompatible_u8_test.vv @@ -0,0 +1,10 @@ +module main + +fn accept_only_u8_references(x &u8) { + println(ptr_str(x)) +} + +fn test_main() { + a := [1, 2, 3] + accept_only_u8_references(&a) +}