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

cgen error on v -autofree run bug.v #16845

Open
spytheman opened this issue Jan 2, 2023 · 1 comment
Open

cgen error on v -autofree run bug.v #16845

spytheman opened this issue Jan 2, 2023 · 1 comment
Labels
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. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Memory Management Bugs/feature requests, that are related to the memory management of the compiler.

Comments

@spytheman
Copy link
Member

V doctor:

OS: linux, Ubuntu 20.04.5 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz
CC version: cc (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0

getwd: /v/vnew
vmodules: /home/delian/.vmodules
vroot: /v/vnew
vexe: /v/vnew/v
vexe mtime: 2023-01-02 14:49:05
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.2 f71572a

Git version: git version 2.39.0
Git vroot status: weekly.2023.01-3-g9bee702c (2 commit(s) behind V master)
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

What did you do?
v -autofree bug.v

import os
import json

struct Syntax {
	name       string
	extensions []string
	fmt_cmd    string
	keywords   []string
	literals   []string
}

fn main() {
	println('loading syntax files...')
	mut syntaxes := []Syntax{}
	files := os.walk_ext('.', '.syntax')
	for file in files {
		syntaxes << json.decode(Syntax, os.read_file(file) or {
			eprintln('    error: cannot load syntax file ${file}: ${err.msg()}')
			'{}'
		}) or {
			eprintln('    error: cannot load syntax file ${file}: ${err.msg()}')
			Syntax{}
		}
	}
	println('${files.len} syntax files loaded')
	dump(syntaxes)
}

What did you expect to see?

A compiled program.

What did you see instead?

#0 23:26:37 ᛋ master /v/vnew❱v -autofree bug.v
==================
/tmp/v_1000/bug.1718565114937288798.tmp.c:18618: error: 'err' undeclared
...
==================
(Use `v -cg` to print the entire error message)

Note, that the same program does compile, and runs fine with just v run bug.v, i.e. the problem is entirely with what code is generated only with -autofree:

loading syntax files...
0 syntax files loaded
[bug.v:26] syntaxes: []
@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Memory Management Bugs/feature requests, that are related to the memory management of the compiler. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Jan 2, 2023
@spytheman
Copy link
Member Author

The following workaround (splitting the 2nd argument to json.decode to its own local variable), fixes compilation with -autofree:

		content := os.read_file(file) or {
			eprintln('    error: cannot load syntax file ${file}: ${err.msg()}')
			'{}'
		}
		syntaxes << json.decode(Syntax, content) or {
			eprintln('    error: cannot load syntax file ${file}: ${err.msg()}')
			Syntax{}
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Memory Management Bugs/feature requests, that are related to the memory management of the compiler.
Projects
None yet
Development

No branches or pull requests

1 participant