Skip to content
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

C compilation error when using string concatenation with autofree #23081

Open
dy-tea opened this issue Dec 6, 2024 · 1 comment
Open

C compilation error when using string concatenation with autofree #23081

dy-tea opened this issue Dec 6, 2024 · 1 comment
Labels
Autofree Bugs/feature requests, that are related to -autofree. Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@dy-tea
Copy link

dy-tea commented Dec 6, 2024

Describe the bug

Wanted to see if autofree would work with my personal project. It is pure V and only depends on the V standard library.

Reproduction Steps

See my repo here: https://github.com/dy-tea/rr-dl
It does compile with v run build.vsh or simply v .
It also successfully compiles with v -prealloc .
It does not compile with v -autofree .

Expected Behavior

Should compile

Current Behavior

================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/main.01JEEZGQD4AGT5628VEM39GYVR.tmp.c:22839: error: '{' expected (got ")")
=================================================================
(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 .

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 de3b184

Environment details (OS name and version, etc.)

V full version: V 0.4.8 de3b184
OS: linux, "CachyOS"
Processor: 12 cpus, 64bit, little endian, 13th Gen Intel(R) Core(TM) i5-1335U

getwd: /home/dylan/Repos/rr-dl
vexe: /home/dylan/Repos/v/v
vexe mtime: 2024-12-06 21:50:48

vroot: OK, value: /home/dylan/Repos/v
VMODULES: OK, value: /home/dylan/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.47.1
Git vroot status: weekly.2024.49-32-gde3b184b
.git/config present: true

CC version: cc (GCC) 14.2.1 20240910
emcc version: N/A
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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.

Huly®: V_0.6-21520

@dy-tea dy-tea added the Bug This tag is applied to issues which reports bugs. label Dec 6, 2024
@felipensp
Copy link
Member

As temporary workaround:

diff --git a/src/main.v b/src/main.v
index 25fd6f7..5fe13ab 100644
--- a/src/main.v
+++ b/src/main.v
@@ -119,9 +119,10 @@ fn main() {
 	// Print fiction info
 	println('') // Leave space before and after print
 	for i, _ in fiction_titles {
-		println(term.hex(color_4, '[') + term.hex(color_2, '${i}') + term.hex(color_4, ']') +
+		t := term.hex(color_4, '[') + term.hex(color_2, '${i}') + term.hex(color_4, ']') +
 			term.hex(color_5, ' ${fiction_titles[i]} ') +
-			term.hex(color_1, '(${fiction_chapter_counts[i]})'))
+			term.hex(color_1, '(${fiction_chapter_counts[i]})')
+		println(t)
 	}
 	println('')
 
@@ -173,9 +174,10 @@ fn main() {
 	}
 
 	// Print some fancy stuff
-	print(term.hex(color_5, '\n${royal_road}') + term.hex(color_3, '\n\n${selected_fiction}') +
+	t := term.hex(color_5, '\n${royal_road}') + term.hex(color_3, '\n\n${selected_fiction}') +
 		term.hex(color_1, '\n${selected_fiction_chapter_count}\n\n') +
-		term.hex(color_3, 'Latest Chapter:') + term.hex(color_1, '\n${chapter_titles.last()}\n\n'))
+		term.hex(color_3, 'Latest Chapter:') + term.hex(color_1, '\n${chapter_titles.last()}\n\n')
+	print(t)
 
 	// Define initial chapter ranges and select all or none
 	mut chapter_begin := if is_select_all { 0 } else { -1 }
@@ -200,8 +202,9 @@ fn main() {
 		}
 
 		for i, n in chapter_search {
-			println(term.hex(color_4, '[') + term.hex(color_2, '${i}') + term.hex(color_4, ']') +
-				term.hex(color_5, ' ${chapter_titles[n]}'))
+			t2 := term.hex(color_4, '[') + term.hex(color_2, '${i}') + term.hex(color_4, ']') +
+				term.hex(color_5, ' ${chapter_titles[n]}')
+			println(t2)
 		}
 
 		chapter_begin_str := if chapter_search.len == 1 { '0' } else { os.input_opt(term.hex(color_3, '\nSelect start chapter by index / first result: ')) or {
@@ -225,8 +228,9 @@ fn main() {
 		}
 
 		for i, n in chapter_search_end {
-			println(term.hex(color_4, '[') + term.hex(color_2, '${i}') + term.hex(color_4, ']') +
-				term.hex(color_5, ' ${chapter_titles[n]}'))
+			t3 := term.hex(color_4, '[') + term.hex(color_2, '${i}') + term.hex(color_4, ']') +
+				term.hex(color_5, ' ${chapter_titles[n]}')
+			println(t3)
 		}
 
 		chapter_end_str := if chapter_search_end.len == 1 { '' } else { os.input_opt(term.hex(color_3, '\nSelect end chapter by index / single chapter: ')) or {
@@ -256,12 +260,14 @@ fn main() {
 	// Chapter ranges
 	mut range := []int{}
 	if chapter_begin == chapter_end {
-		println(term.hex(color_5, 'Downloading chapter') + term.hex(color_3, ' ${chapter_begin}'))
+		t4 := term.hex(color_5, 'Downloading chapter') + term.hex(color_3, ' ${chapter_begin}')
+		println(t4)
 		range << chapter_begin
 	} else {
-		println(term.hex(color_5, 'Downloading chapters') +
+		t5 := term.hex(color_5, 'Downloading chapters') +
 			term.hex(color_3, ' ${chapter_begin} ') + term.hex(color_5, 'to') +
-			term.hex(color_3, ' ${chapter_end}') + term.hex(color_5, ':'))
+			term.hex(color_3, ' ${chapter_end}') + term.hex(color_5, ':')
+		println(t5)
 		for i in chapter_begin .. chapter_end + 1 { // For loops cannot loop inclusively
 			range << i // This is very dumb
 		}
@@ -274,8 +280,10 @@ fn main() {
 	for i in range {
 		chapter_link := base_url + selected_href + '/chapter/' + chapter_ids[i] + '/' +
 			chapter_slugs[i]
-		println(term.hex(color_5, 'Downloading:') + ' ${term.hex(color_3, chapter_titles[i])}')
-		println(term.hex(color_3, 'Link:') + ' ${term.hex(color_1, chapter_link)}')
+		t6 := term.hex(color_5, 'Downloading:') + ' ${term.hex(color_3, chapter_titles[i])}'
+		println(t6)
+		t7 := term.hex(color_3, 'Link:') + ' ${term.hex(color_1, chapter_link)}'
+		println(t7)
 
 		resp_chapter := http.get_text(chapter_link)
 
@@ -314,13 +322,15 @@ fn main() {
 		}
 
 		if os.is_writable(download_directory) {
-			os.write_file(download_directory + '/' + name_chapter(chapter_titles[i]) + '.' +
-				file_extension, chapter_content) or { panic(err) }
+			t8 := download_directory + '/' + name_chapter(chapter_titles[i]) + '.' +
+				file_extension
+			os.write_file(t8, chapter_content) or { panic(err) }
 		} else {
 			panic(term.fail_message('ERROR: Insufficient permissons to write to specified directory'))
 		}
 	}
 	// Print elapsed time during downloade
-	println(term.hex(color_3, '\nFinished download in ') +
-		term.hex(color_1, '${download_timer.elapsed().milliseconds()}') + term.hex(color_3, 'ms'))
+	t9 := term.hex(color_3, '\nFinished download in ') +
+		term.hex(color_1, '${download_timer.elapsed().milliseconds()}') + term.hex(color_3, 'ms')
+	println(t9)
 }

@felipensp felipensp changed the title C compilation error when compiling pure V code with autofree C compilation erro when using string concatenation with autofree Dec 7, 2024
@felipensp felipensp added Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Autofree Bugs/feature requests, that are related to -autofree. labels Dec 7, 2024
@dy-tea dy-tea changed the title C compilation erro when using string concatenation with autofree C compilation error when using string concatenation with autofree Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Autofree Bugs/feature requests, that are related to -autofree. Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

No branches or pull requests

2 participants