-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simple generic structure declaration error #21989
Comments
that is, if a generic function returns a generic structure, V cannot deduce that it is necessary to define a generic structure, that is, there is no description of it in C and it complains about the C code. |
its good C error |
No, C errors are never good. V should at least try to catch it and give a nicer error, before sending it to the C compiler. |
However, a more complete example will be required before anything can be done about this. With the partial code you show above, there are lots of V errors, and the C compiler is never called at all:
|
@JalonSolov Should be working here https://play.vlang.io/p/8170c26143 |
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 u32) 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 map<O>(p TParser[u8], f TF[O]) TParser[O] {
return fn [p, f] <O>(i []u8) !ParserResult[O] {
r:=p(i)!
return ParserResult{i:r.i, o:f(r.o)}
}
}
fn test_1() {
input := '10_ttt_uuuu_qqq_'.bytes()
nnn:=take_part(2)
println(' it is: ${nnn(input)!}')
fnf := fn(i[]u8) int { return 1 }
n := map[int](nnn, fnf)
assert ['nn'] == ['ttt_', 'uuuu_', 'qqq_']
}
`
--- Testing... -----------------------------------------------------------------------------------------------------------------------------------------------------------
FAIL 0.000 ms /home/prof/projects/v/parselona/src/parselona_test.v
>> compilation failed:
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/tsession_704f1d69f740_01J4Q5YZCTYXCVAK9ESWAGAX7W/parselona_test.01J4Q5Z0T9ZS2Q9JCXM6E0YW4D.tmp.c:106: error: identifier expected
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error:
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
`
|
I updated the text |
I confirm that your updated example, does produce a C error. |
V doctor:
What did you do?
./v -g -o vdbg cmd/v && ./vdbg src/parselona_test.v
What did you expect to see?
test complit
What did you see instead?
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.
The text was updated successfully, but these errors were encountered: