You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Passing a module-qualified static method (mod.Type.method) as a first-class function value (e.g. as a map/filter callback) is misresolved by the compiler. The same expression works correctly when the type is declared in the same module, but across module boundaries it is misinterpreted as an enum value.
This was originally observed in the wild as a C-compilation failure (the static method name was emitted as a bare, undefined C identifier). On current master it surfaces one step earlier as a checker error that wrongly claims the struct is an enum.
mtime.MTime is a struct with a static method from, not an enum. The compiler parses mtime.MTime.from as EnumVal{enum: mtime.MTime, variant: from}.
The explicit-call form fails the same way:
ms:= nums.map(mtime.MTime.from(it))
// error: unknown function: mtime.MTime__static__from// type mismatch, `mtime.MTime__static__from` does not return anything
Expected
Cross-module behaves like same-module. The following same-module program compiles and runs correctly (prints 6):
So the static-method-as-callback feature itself works — it only breaks when the type is reached through a module qualifier.
Originally observed C output (from a real bug report)
A .map() over []time.Time producing []common.mtime.MTime emitted the static factory as a bare identifier instead of a call, which then failed at the C compiler:
common__mtime__MTime_t25=common__mtime__MTime__static__from; // undefined: should be ..._from(it)builtin__array_push_noscan((array*)&_t24, &_t25);
error: 'common__mtime__MTime__static__from' undeclared (first use in this function)
Environment
V 0.5.1
Reproduced on macOS; original report on Linux (cc)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
Description
Passing a module-qualified static method (
mod.Type.method) as a first-class function value (e.g. as amap/filtercallback) is misresolved by the compiler. The same expression works correctly when the type is declared in the same module, but across module boundaries it is misinterpreted as an enum value.This was originally observed in the wild as a C-compilation failure (the static method name was emitted as a bare, undefined C identifier). On current master it surfaces one step earlier as a checker error that wrongly claims the struct is an enum.
Reproduction
mtime/mtime.v:main.v:Actual
mtime.MTimeis a struct with a static methodfrom, not an enum. The compiler parsesmtime.MTime.fromasEnumVal{enum: mtime.MTime, variant: from}.The explicit-call form fails the same way:
Expected
Cross-module behaves like same-module. The following same-module program compiles and runs correctly (prints
6):So the static-method-as-callback feature itself works — it only breaks when the type is reached through a module qualifier.
Originally observed C output (from a real bug report)
A
.map()over[]time.Timeproducing[]common.mtime.MTimeemitted the static factory as a bare identifier instead of a call, which then failed at the C compiler:Environment
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.