1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix mutable receiver type calling mapping function causes C error (fix #14230) (#14696)

This commit is contained in:
ChAoS_UnItY 2022-06-06 23:34:04 +08:00 committed by GitHub
parent 778fe2cde0
commit ce26d5bc5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View File

@ -345,10 +345,15 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) {
} }
left_type := if node.left_type.has_flag(.shared_f) { left_type := if node.left_type.has_flag(.shared_f) {
node.left_type.clear_flag(.shared_f).deref() node.left_type.clear_flag(.shared_f).deref()
} else if node.left_type.is_ptr() {
node.left_type.deref()
} else { } else {
node.left_type node.left_type
} }
g.write('${g.typ(left_type)} ${tmp}_orig = ') g.write('${g.typ(left_type)} ${tmp}_orig = ')
if !node.left_type.has_flag(.shared_f) && node.left_type.is_ptr() {
g.write('*')
}
g.expr(node.left) g.expr(node.left)
if node.left_type.has_flag(.shared_f) { if node.left_type.has_flag(.shared_f) {
g.write('->val') g.write('->val')

View File

@ -0,0 +1,3 @@
[1, 0, 0]
[0, 1, 0]
[0, 0, 1]

View File

@ -0,0 +1,18 @@
fn (mut a [][]f32) str() string {
return a.map(it.str()).join('\n')
}
fn identity(n int) [][]f32 {
mut res := [][]f32{len: n, init: []f32{len: n, init: 0.0}}
for i in 0 .. n {
res[i][i] = 1.0
}
return res
}
fn main() {
a := identity(3)
println(a)
}