Skip to content

type_resolver: fix comptimecall resolving aliased method#25254

Merged
spytheman merged 1 commit into
vlang:masterfrom
felipensp:fix_veb_static_method_resolve
Sep 8, 2025
Merged

type_resolver: fix comptimecall resolving aliased method#25254
spytheman merged 1 commit into
vlang:masterfrom
felipensp:fix_veb_static_method_resolve

Conversation

@felipensp

Copy link
Copy Markdown
Member

Fix #25253

@felipensp felipensp marked this pull request as ready for review September 8, 2025 12:24
@spytheman

Copy link
Copy Markdown
Contributor

Hm, interesting ... the compilation error for the issue is gone, but it still does not behave as it should, perhaps due to an unrelated bug:

import veb

pub struct Context {
    veb.Context
}

pub struct App {
    veb.Middleware[Context]
    veb.Controller
    veb.StaticHandler
}

pub fn (mut app AliasApp) index(mut ctx Context) veb.Result {
    return ctx.text('Hello V!')
}

type AliasApp = App
type AliasContext = Context

mut app := &AliasApp{}
veb.run_at[AliasApp, AliasContext](mut app,
    port: 12343
    family: .ip
)!

This produces:

VV_LOC _result_Map_string_veb__Route veb__generate_routes_T_main__AliasApp_main__AliasContext(main__AliasApp* app) {
    Map_string_veb__Route routes = new_map(sizeof(string), sizeof(veb__Route), &map_hash_string, &map_eq_string, &map_clone_string, &map_free_str$
    ;
    _v_dump_expr_string(_S("/home/delian/v/vlib/veb/veb.v"), 41, _S("typeof[A]()"), _S("AliasApp"));
    /* $for method in main.App.methods */ {
    }// $for
    _result_Map_string_veb__Route _t1 = {0};
    _result_ok(&(Map_string_veb__Route[]) { routes }, (_result*)(&_t1), sizeof(Map_string_veb__Route));
    return _t1;
}

(after a small modification to vlib/veb/veb.v:38 to add dump(typeof[A]()) )

It appears that $for method in A.methods { could not find the method, defined on the alias,
so the routing did not work 🤔.

@spytheman

Copy link
Copy Markdown
Contributor

The compiler did know the full aliased type (it resolved properly the generate_routes method parameter, as well as the typeof[A]() call).

It seems that only the $for x in A.methods { construct was wrong to not iterate over all the defined methods.

@vlang vlang deleted a comment from huly-for-github Bot Sep 8, 2025
@spytheman spytheman merged commit 847c15e into vlang:master Sep 8, 2025
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cgen error: could not find method, for compiling a veb program with an app alias, with defined index route on the unaliased App type

2 participants