From 29e962749a17d85c52d72b7d29d808cf74d55c02 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 11 Mar 2026 13:54:18 +0300 Subject: [PATCH] cgen: incorrect Auto De-referencing of &net.TcpConn in Map Access (fixes #21067) --- vlib/v/debug/tests/map_nested_ref_mut.expect | 9 +++++++++ vlib/v/debug/tests/map_nested_ref_mut.vv | 12 ++++++++++++ .../map_nested_reference_value_test.v | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 vlib/v/debug/tests/map_nested_ref_mut.expect create mode 100644 vlib/v/debug/tests/map_nested_ref_mut.vv create mode 100644 vlib/v/tests/builtin_maps/map_nested_reference_value_test.v diff --git a/vlib/v/debug/tests/map_nested_ref_mut.expect b/vlib/v/debug/tests/map_nested_ref_mut.expect new file mode 100644 index 000000000..171ca6c0f --- /dev/null +++ b/vlib/v/debug/tests/map_nested_ref_mut.expect @@ -0,0 +1,9 @@ +#!/usr/bin/env expect +source "common.tcl" + +expect "Break on *main* main in ${test_file}:9\r\n" +expect "${test_file}:9 vdbg> " +send "p connection\n" +expect "connection = * (&net.TcpConn)" +send "q\n" +expect eof diff --git a/vlib/v/debug/tests/map_nested_ref_mut.vv b/vlib/v/debug/tests/map_nested_ref_mut.vv new file mode 100644 index 000000000..0f119a534 --- /dev/null +++ b/vlib/v/debug/tests/map_nested_ref_mut.vv @@ -0,0 +1,12 @@ +import net + +fn main() { + mut con_list := map[string]map[string]&net.TcpConn{} + con_list['foo'] = { + 'bar': &net.TcpConn{} + } + for _, mut connection in unsafe { con_list['foo'] } { + $dbg; + dump(connection) + } +} diff --git a/vlib/v/tests/builtin_maps/map_nested_reference_value_test.v b/vlib/v/tests/builtin_maps/map_nested_reference_value_test.v new file mode 100644 index 000000000..0504f3a1e --- /dev/null +++ b/vlib/v/tests/builtin_maps/map_nested_reference_value_test.v @@ -0,0 +1,19 @@ +import net + +fn accept_mut_tcp_conn(mut conn net.TcpConn) bool { + return true +} + +fn test_nested_map_tcpconn_reference_value_for_in_mut_type() { + mut con_list := map[string]map[string]&net.TcpConn{} + conn := &net.TcpConn{} + con_list['foo'] = { + 'bar': conn + } + + for _, mut connection in unsafe { con_list['foo'] } { + assert typeof(connection).name == '&net.TcpConn' + assert accept_mut_tcp_conn(mut connection) + assert voidptr(connection) == voidptr(conn) + } +} -- 2.39.5