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

Unhandled Exception when setting const to function that returns error or struct #23555

Open
islonely opened this issue Jan 23, 2025 · 2 comments
Labels
C gen declarations order Wrong order of declarations in CGEN. Status: Confirmed This bug has been confirmed to be valid by a contributor.

Comments

@islonely
Copy link
Contributor

islonely commented Jan 23, 2025

V version: V 0.4.9 4e68a86, press to see full `v doctor` output
V full version V 0.4.9 4b6b852.4e68a86
OS windows, Microsoft Windows 11 Pro 22631 64-bit
Processor 16 cpus, 64bit, little endian, Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz
Memory 21.33GB/31.87GB
V executable C:\Users\imado\v\v.exe
V last modified time 2025-01-22 05:15:49
V home dir OK, value: C:\Users\imado\v
VMODULES OK, value: C:\Users\imado.vmodules
VTMP OK, value: C:\Users\imado\AppData\Local\Temp\v_0
Current working dir OK, value: C:\Users\imado\Documents\GitHub\bibleclock
Git version git version 2.33.1.windows.1
V git status weekly.2024.52-184-g4e68a860 (3 commit(s) behind V master)
.git/config present true
cc version N/A
gcc version gcc (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders) 12.2.0
clang version (built by Brecht Sanders) clang version 15.0.7
msvc version N/A
tcc version tcc version 0.9.27 (x86_64 Windows)
tcc git status thirdparty-windows-amd64 b425ac82
emcc version N/A
glibc version ldd (cygwin) 3.3.6

What did you do?
./v -g -o vdbg cmd/v && ./vdbg C:\Users\imado\Documents\test.v && C:\Users\imado\Documents\test.exe

const something = new(.foo) or { panic(err.str()) }

const bar = {
	Foo.foo: 'some_string'
}

enum Foo {
	foo
}

struct Something {}

fn new(foo Foo) !Something {
	println(bar[foo])
	return Something{}
}

fn main() {
	println(something)
}

What did you see?

Unhandled Exception 0x149f830
C:/Users/imado/AppData/Local/Temp/v_0/test.01JJ8PWZA4MC3FRJH1XHM3JC9Q.tmp.c:4276: at print_backtrace_skipping_top_frames_tcc: Backtrace
C:/Users/imado/AppData/Local/Temp/v_0/test.01JJ8PWZA4MC3FRJH1XHM3JC9Q.tmp.c:4262: by print_backtrace_skipping_top_frames
C:/Users/imado/AppData/Local/Temp/v_0/test.01JJ8PWZA4MC3FRJH1XHM3JC9Q.tmp.c:4839: by unhandled_exception_handler
7fffdada80ba : by ???
RUNTIME ERROR: invalid memory access

What did you expect to see?

Expected no "unhandled exception" and for "some_string\nSomething{}" to be printed.

Note

Moving const something to below const bar lets the program compile and run fine.

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.

Copy link

Connected to Huly®: V_0.6-21983

@felipensp
Copy link
Member

To fix it you have to change the order of declaration to:

const bar = {
	Foo.foo: 'some_string'
}
const something = new(.foo) or { panic(err.str()) }

@felipensp felipensp added Status: Confirmed This bug has been confirmed to be valid by a contributor. C gen declarations order Wrong order of declarations in CGEN. labels Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C gen declarations order Wrong order of declarations in CGEN. Status: Confirmed This bug has been confirmed to be valid by a contributor.
Projects
None yet
Development

No branches or pull requests

2 participants