v icon indicating copy to clipboard operation
v copied to clipboard

C builder error

Open PibePlayer opened this issue 3 years ago • 3 comments

V doctor:

sh: can't open /proc/1/mountinfo: No such file or directory
OS: linux, Error: cat: /proc/version: Permission denied
 (chroot)
Processor: 8 cpus, 64bit, little endian, aarch64
CC version: clang version 11.1.0 (https://github.com/termux/termux-packages 07320e6ed6e28aafc95d8af42d0da9a33bc3b79a)

getwd: /data/data/com.termux/files/home/PriceGBSorterML
vmodules: /data/data/com.termux/files/home/.vmodules
vroot: /data/data/com.termux/files/home/v
vexe: /data/data/com.termux/files/home/v/v
vexe mtime: 2021-10-11 20:47:32
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.4 0f7dfb9.3c8be0d

Git version: git version 2.31.0
Git vroot status: weekly.2021.41-2-g3c8be0db
.git/config present: true
thirdparty/tcc status: thirdparty-unknown-unknown de82a130

What did you do? v -g -o vdbg cmd/v && vdbg PriceGBSorter.v

module main

import net.http
import x.json2
import regex
import os

struct HDD {
	name string
	price f32
	size int
	permalink string
}

fn main() {
	println('Hello World!')
	mut request := http.Request{
		url: "https://api.mercadolibre.com/sites/MLA/search?category=MLA1672",
		method: http.Method.get
	}
	request.add_header(http.CommonHeader.authorization, "Bearer TG-6163150ead3e6b000762d365-134063224")
	response := request.do() ?

	query := r'[\d]+(?:\.|,[\d]{1,4})?\s*(?P<denom>(TB)|(GB))'
	mut re := regex.regex_opt(query) or { panic(err) }
	println(re.get_query())
	//re.compile_opt() ?

	raw := json2.raw_decode(response.text) ?
	mapped := raw.as_map()
	//println(response.text)

	mut str := ""
	mut products := []HDD { cap: 1000 }
	for product in mapped['results']?.arr() {
		//println(mapped['results']?.arr())
		str = product.as_map()['title']?.str().to_upper()
		println(str)
		start, end := re.find(str)
		println(start)
		println(end)
		if start != -1 {
			println(str[start..end])
			println(str[start..end-2])
			println(str[end-2..end])

			mut size := str[start..end-2].int()
			if str[end-2..end] == "TB" {
				size *= 1024
			}

			products << HDD {
				name: str,
				size: size,
				price: product.as_map()['price']?.int()
			}
		}
	}

	for product in products {
		println(product.name)
	}
	os.write_file("/data/data/com.termux/files/home/PriceGBSorterML/test.json", response.text) ?
	//println(response.text)
}

What did you expect to see?

A working program

What did you see instead?

==================
   ^~~~~~~~~~~~~~~
/data/data/com.termux/files/usr/tmp/v/PriceGBSorter.1122526317027266242.tmp.c:27856:137: error: cannot take the address of an rvalue of type 'Map_string_x__json2__Any' (aka 'struct map')
                        array_push((array*)&products, _MOV((main__HDD[]){ (main__HDD){.name = str,.price = x__json2__Any_int((*(x__json2__Any*)map_get((map*)&x__json2__Any_as_map(product), &(string[]){_SLIT("price")}, &(x__json2__Any[]){ {0} }))),.size = size,.permalink = (string){.str=(byteptr)"", .is_lit=1},} }));
                                                                                                                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43 warnings and 1 error generated.
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

PibePlayer avatar Oct 11 '21 21:10 PibePlayer

...
DISCO SóLIDO INTERNO WESTERN DIGITAL  SN570 WDS250G3B0C 250GB
DISCO DURO EXTERNO SEAGATE EXPANSION STKM4000400 4TB NEGRO
DISCO DURO INTERNO WESTERN DIGITAL WD SCORPIO BLUE WD3200BPVT 320GB AZUL
DISCO SóLIDO INTERNO PNY SSD7CS900-120-RB 120GB NEGRO
V panic: result not set (failed to open file "/data/data/com.termux/files/home/PriceGBSorterML/test.json")
v hash: 74613bd
/tmp/v_1000/bug.1924944929689686017.tmp.c:11287: at _v_panic: Backtrace
/tmp/v_1000/bug.1924944929689686017.tmp.c:11257: by panic_result_not_set
/tmp/v_1000/bug.1924944929689686017.tmp.c:33827: by main__main
/tmp/v_1000/bug.1924944929689686017.tmp.c:34556: by main

seems to be already fixed to me.

ghost avatar Nov 19 '22 03:11 ghost

...
DISCO SóLIDO INTERNO WESTERN DIGITAL  SN570 WDS250G3B0C 250GB
DISCO DURO EXTERNO SEAGATE EXPANSION STKM4000400 4TB NEGRO
DISCO DURO INTERNO WESTERN DIGITAL WD SCORPIO BLUE WD3200BPVT 320GB AZUL
DISCO SóLIDO INTERNO PNY SSD7CS900-120-RB 120GB NEGRO
V panic: result not set (failed to open file "/data/data/com.termux/files/home/PriceGBSorterML/test.json")
v hash: 74613bd
/tmp/v_1000/bug.1924944929689686017.tmp.c:11287: at _v_panic: Backtrace
/tmp/v_1000/bug.1924944929689686017.tmp.c:11257: by panic_result_not_set
/tmp/v_1000/bug.1924944929689686017.tmp.c:33827: by main__main
/tmp/v_1000/bug.1924944929689686017.tmp.c:34556: by main

seems to be already fixed to me.

I'll check later, thanks for the heads up!

PibePlayer avatar Nov 19 '22 17:11 PibePlayer

Already fixed?

felipensp avatar Mar 23 '23 20:03 felipensp