markused: fix generic method call mark (fix #24395) (#24399)

This commit is contained in:
Felipe Pena 2025-05-04 08:58:41 -03:00 committed by GitHub
parent 2bd2d00caf
commit a831ec77d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 42 additions and 4 deletions

View File

@ -705,7 +705,8 @@ pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
w.expr(node.left) w.expr(node.left)
w.or_block(node.or_block) w.or_block(node.or_block)
fn_name := node.fkey() mut fn_name := node.fkey()
mut receiver_typ := node.receiver_type
if w.used_fns[fn_name] { if w.used_fns[fn_name] {
return return
} }
@ -735,12 +736,13 @@ pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
&& !node.receiver_concrete_type.has_flag(.generic) { && !node.receiver_concrete_type.has_flag(.generic) {
// if receiver is generic, then cgen requires `node.receiver_type` to be T. // if receiver is generic, then cgen requires `node.receiver_type` to be T.
// We therefore need to get the concrete type from `node.receiver_concrete_type`. // We therefore need to get the concrete type from `node.receiver_concrete_type`.
fkey := '${int(node.receiver_concrete_type)}.${node.name}' fn_name = '${int(node.receiver_concrete_type)}.${node.name}'
w.mark_fn_as_used(fkey) receiver_typ = node.receiver_concrete_type
w.mark_fn_as_used(fn_name)
} }
stmt := w.all_fns[fn_name] or { return } stmt := w.all_fns[fn_name] or { return }
if stmt.name == node.name { if stmt.name == node.name {
if !node.is_method || node.receiver_type == stmt.receiver.typ { if !node.is_method || receiver_typ == stmt.receiver.typ {
w.stmts(stmt.stmts) w.stmts(stmt.stmts)
} }
} }

View File

@ -0,0 +1,36 @@
import veb
import x.json2
pub struct Context {
veb.Context
}
pub struct App {
veb.Middleware[Context]
}
@['/'; POST]
fn (app &App) index(mut ctx Context) veb.Result {
j := json2.raw_decode(ctx.req.data) or { return ctx.request_error('error') }
m := j.as_map()
myarr := m['myarr'] or { panic(error) }
m2 := myarr.arr()
for mc in m2 {
parts := mc.arr()
// Compiler error occurs here -->
first := parts[0].str()
second := parts[1].str()
third := parts[2].str()
println('1. ${first}, 2. ${second}, 3. ${third}')
}
return ctx.ok('ok')
}
fn main() {
_ := &App{}
}