Repository navigation
cannot return a function from a generic function #22011
Copy link
Copy link
Closed
Labels
BugThis tag is applied to issues which reports bugs.This tag is applied to issues which reports bugs.Generics[T]Bugs/feature requests, that are related to the V generics.Bugs/feature requests, that are related to the V generics.Unit: CheckerBugs/feature requests, that are related to the type checker.Bugs/feature requests, that are related to the type checker.
Description
Describe the bug
module parselona
pub struct ParserResult[O] {
i []u8
o O
}
type TParser[O] = fn([]u8) !ParserResult[O]
type TF[O] = fn([]u8) O
fn take_part(count int) TParser[[]u8] {
return fn [count] (i []u8) !ParserResult[[]u8] {
if i.len<count { return error('error len: ${i}') }
return ParserResult[[]u8] {
i: i[count..],
o: i[..count],
}
}
}
fn fmap<O>(p TParser[[]u8], f TF[O]) TParser[O] {
return fn [p, f] <O>(i []u8) !ParserResult[O] {
r:=p(i)!
return ParserResult[O]{i:r.i, o:f<O>(r.o)}
}
}
fn test_1() {
input := '10_ttt_uuuu_qqq_'.bytes()
f := ParserResult[int] {
i: [u8(1),u8(2)]
o: 1
}
nnn:=take_part(2)
println('hhhhh ${nnn(input)!}')
fnf := fn(i[]u8) int { return 1 }
n := fmap[int](nnn, fnf)
f1 := n(input) or { println('errr') return }
println('hhhhh ${f1}')
assert ['nn'] == ['ttt_', 'uuuu_', 'qqq_']
}Reproduction Steps
v test parselona_test.v
Expected Behavior
complit test
Current Behavior
FAIL 0.000 ms /home/prof/projects/v/parselona/src/parselona_test.v
compilation failed:
parselona.v:49:9: error: cannot use `fn ([]u8) !parselona.ParserResult[O]` as type `fn ([]u8) !parselona.ParserResult[int]` in return argument
47 |
48 | fn fmap<O>(p TParser[[]u8], f TF[O]) TParser[O] {
49 | return fn [p, f] <O>(i []u8) !ParserResult[O] {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50 | r:=p(i)!
51 | return ParserResult[O]{i:r.i, o:f<O>(r.o)}
Possible Solution
for some reason type parametr not expansion
Additional Information/Context
No response
V version
V 0.4.7 3ca5bc3
Environment details (OS name and version, etc.)
Linux Mint 22
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugThis tag is applied to issues which reports bugs.This tag is applied to issues which reports bugs.Generics[T]Bugs/feature requests, that are related to the V generics.Bugs/feature requests, that are related to the V generics.Unit: CheckerBugs/feature requests, that are related to the type checker.Bugs/feature requests, that are related to the type checker.
Activity
Cergoo commentedon Aug 8, 2024
see #13253
medvednikov commentedon Aug 9, 2024
A simple reproducible example:
medvednikov commentedon Aug 9, 2024
It's related to @yuyi98's fix #15529
cannot return a function from a generic function (fixes #22011)
cannot return a function from a generic function (fixes #22011)
cannot return a function from a generic function (fixes #22011)
checker: cannot return a function from a generic function (fixes #22011)
checker: cannot return a function from a generic function (fixes vlan…