mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
markused: fix generic map index (fix #25012) (#25022)
Some checks are pending
Graphics CI / gg-regressions (push) Waiting to run
vlib modules CI / build-module-docs (push) Waiting to run
native backend CI / native-backend-ubuntu (push) Waiting to run
native backend CI / native-backend-windows (push) Waiting to run
Shy and PV CI / v-compiles-puzzle-vibes (push) Waiting to run
Sanitized CI / sanitize-undefined-clang (push) Waiting to run
Sanitized CI / sanitize-undefined-gcc (push) Waiting to run
Sanitized CI / tests-sanitize-address-clang (push) Waiting to run
Sanitized CI / sanitize-address-msvc (push) Waiting to run
Sanitized CI / sanitize-address-gcc (push) Waiting to run
Sanitized CI / sanitize-memory-clang (push) Waiting to run
sdl CI / v-compiles-sdl-examples (push) Waiting to run
Time CI / time-linux (push) Waiting to run
Time CI / time-macos (push) Waiting to run
Time CI / time-windows (push) Waiting to run
toml CI / toml-module-pass-external-test-suites (push) Waiting to run
Tools CI / tools-linux (clang) (push) Waiting to run
Tools CI / tools-linux (gcc) (push) Waiting to run
Tools CI / tools-linux (tcc) (push) Waiting to run
Tools CI / tools-macos (clang) (push) Waiting to run
Tools CI / tools-windows (gcc) (push) Waiting to run
Tools CI / tools-windows (msvc) (push) Waiting to run
Tools CI / tools-windows (tcc) (push) Waiting to run
Tools CI / tools-docker-ubuntu-musl (push) Waiting to run
vab CI / vab-compiles-v-examples (push) Waiting to run
vab CI / v-compiles-os-android (push) Waiting to run
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Waiting to run
wasm backend CI / wasm-backend (windows-2022) (push) Waiting to run
Some checks are pending
Graphics CI / gg-regressions (push) Waiting to run
vlib modules CI / build-module-docs (push) Waiting to run
native backend CI / native-backend-ubuntu (push) Waiting to run
native backend CI / native-backend-windows (push) Waiting to run
Shy and PV CI / v-compiles-puzzle-vibes (push) Waiting to run
Sanitized CI / sanitize-undefined-clang (push) Waiting to run
Sanitized CI / sanitize-undefined-gcc (push) Waiting to run
Sanitized CI / tests-sanitize-address-clang (push) Waiting to run
Sanitized CI / sanitize-address-msvc (push) Waiting to run
Sanitized CI / sanitize-address-gcc (push) Waiting to run
Sanitized CI / sanitize-memory-clang (push) Waiting to run
sdl CI / v-compiles-sdl-examples (push) Waiting to run
Time CI / time-linux (push) Waiting to run
Time CI / time-macos (push) Waiting to run
Time CI / time-windows (push) Waiting to run
toml CI / toml-module-pass-external-test-suites (push) Waiting to run
Tools CI / tools-linux (clang) (push) Waiting to run
Tools CI / tools-linux (gcc) (push) Waiting to run
Tools CI / tools-linux (tcc) (push) Waiting to run
Tools CI / tools-macos (clang) (push) Waiting to run
Tools CI / tools-windows (gcc) (push) Waiting to run
Tools CI / tools-windows (msvc) (push) Waiting to run
Tools CI / tools-windows (tcc) (push) Waiting to run
Tools CI / tools-docker-ubuntu-musl (push) Waiting to run
vab CI / vab-compiles-v-examples (push) Waiting to run
vab CI / v-compiles-os-android (push) Waiting to run
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Waiting to run
wasm backend CI / wasm-backend (windows-2022) (push) Waiting to run
This commit is contained in:
parent
f834855cb5
commit
198ecd09bc
2 changed files with 25 additions and 4 deletions
|
@ -628,7 +628,7 @@ fn (mut w Walker) expr(node_ ast.Expr) {
|
||||||
w.expr(node.expr)
|
w.expr(node.expr)
|
||||||
w.mark_by_type(node.expr_type)
|
w.mark_by_type(node.expr_type)
|
||||||
w.uses_guard = true
|
w.uses_guard = true
|
||||||
if node.expr_type != 0 && !w.uses_str_index_check
|
if node.expr_type != 0 && !w.uses_str_index_check && node.expr is ast.IndexExpr
|
||||||
&& w.table.final_sym(node.expr_type).kind in [.u8, .string] {
|
&& w.table.final_sym(node.expr_type).kind in [.u8, .string] {
|
||||||
w.uses_str_index_check = true
|
w.uses_str_index_check = true
|
||||||
}
|
}
|
||||||
|
@ -1296,9 +1296,6 @@ fn (mut w Walker) mark_resource_dependencies() {
|
||||||
if w.uses_mem_align {
|
if w.uses_mem_align {
|
||||||
w.fn_by_name('memdup_align')
|
w.fn_by_name('memdup_align')
|
||||||
}
|
}
|
||||||
if w.uses_guard || w.uses_check_index {
|
|
||||||
w.fn_by_name('error')
|
|
||||||
}
|
|
||||||
if w.uses_spawn {
|
if w.uses_spawn {
|
||||||
w.fn_by_name('malloc')
|
w.fn_by_name('malloc')
|
||||||
w.fn_by_name('tos3')
|
w.fn_by_name('tos3')
|
||||||
|
@ -1407,6 +1404,9 @@ fn (mut w Walker) mark_resource_dependencies() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if w.uses_guard || w.uses_check_index {
|
||||||
|
w.fn_by_name('error')
|
||||||
|
}
|
||||||
if w.uses_append {
|
if w.uses_append {
|
||||||
ref_array_idx_str := int(ast.array_type.ref()).str()
|
ref_array_idx_str := int(ast.array_type.ref()).str()
|
||||||
w.fn_by_name(ref_array_idx_str + '.push')
|
w.fn_by_name(ref_array_idx_str + '.push')
|
||||||
|
|
21
vlib/v/tests/generics/struct_generic_map_index_test.v
Normal file
21
vlib/v/tests/generics/struct_generic_map_index_test.v
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
pub struct Set[T] {
|
||||||
|
mut:
|
||||||
|
elements map[T]u8
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (l Set[T]) == (r Set[T]) bool {
|
||||||
|
if l.elements.len != r.elements.len {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for key, l_val in l.elements {
|
||||||
|
r_val := r.elements[key] or { return false }
|
||||||
|
if l_val != r_val {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
_ := Set[int]{}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue