-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
cgen error: cannot convert 'struct string' to 'long' #25896
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.
Description
Describe the bug
generic T function may fail with strings.write_string but not strings.writeln.
found by PR #25857
Reproduction Steps
g.v
module main
import strings
pub struct MyStruct[T] {
pub mut:
result T
id string
}
fn main() {
x := MyStruct[int]{}
y := MyStruct[string]{}
dump(x.indent_str())
dump(y.indent_str())
}
pub fn (it MyStruct[T]) indent_str[T]() string {
mut res := strings.new_builder(128)
res.write_string('${it.result}')
// following is OK
// res.writeln('${it.result}')
return res.str()
}v g.v
Expected Behavior
compile ok
Current Behavior
$ v g.v
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/g.01KBMWV9MNPR8A6ZW47790YW53.tmp.c:5033: error: cannot convert 'struct string' to 'long'
=================================================================
Try passing `-g` when compiling, to see a .v file:line information, that correlates more with the C error.
(Alternatively, pass `-show-c-output`, to print the full C error message).
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 .
Possible Solution
use writeln instead of write_string, it will pass compile
Additional Information/Context
No response
V version
V 0.4.12 dafa6fd
Environment details (OS name and version, etc.)
| V full version | V 0.4.12 dafa6fd |
|---|---|
| OS | linux, Ubuntu 24.04.3 LTS |
| Processor | 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz |
| Memory | 6.54GB/15.51GB |
| V executable | /media/HD/github/kbkpbot/v/v |
| V last modified time | 2025-12-04 14:35:47 |
| V home dir | OK, value: /media/HD/github/kbkpbot/v |
| VMODULES | OK, value: /home/mars/.vmodules |
| VTMP | OK, value: /tmp/v_1000 |
| Current working dir | OK, value: /home/mars/v/bug/autostr |
| Git version | git version 2.43.0 |
| V git status | weekly.2025.46-135-gdafa6fd0 |
| .git/config present | true |
| cc version | cc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 |
| gcc version | gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 |
| clang version | Ubuntu clang version 18.1.3 (1ubuntu1) |
| tcc version | tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux) |
| tcc git status | thirdparty-linux-amd64 696c1d84 |
| emcc version | N/A |
| glibc version | ldd (Ubuntu GLIBC 2.39-0ubuntu8.6) 2.39 |
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.