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

fn example<T>(data []T) [][]T causes panic with compiler bug in explanation #7753

Closed
natemcintosh opened this issue Dec 31, 2020 · 2 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@natemcintosh
Copy link

$ v doctor
OS: macos, Mac OS X, 10.15.6, 19G2531
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
CC version: Apple clang version 12.0.0 (clang-1200.0.32.28)

getwd: /Users/natemcintosh/Documents/dev/vlang_examples
vmodules: /Users/natemcintosh/.vmodules
vroot: /Users/natemcintosh/Documents/dev/v
vexe: /Users/natemcintosh/Documents/dev/v/v
vexe mtime: 2020-12-31 13:38:23
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.1 3e655d6.f7b3ed2

Git version: git version 2.24.3 (Apple Git-128)
Git vroot status: 0.2-195-gf7b3ed2f (1 commit(s) behind V master)
.git/config present: true
thirdparty/tcc status: thirdparty-macos-amd64 689c8a02

What did you do?
In a file example.v

fn example<T>(data []T) [][]T {
	return [data]
}

fn main() {
	data := [1, 2, 3]
	d2 := example(data)
	println('$d2') // comment this line out and the crash does not occur
}

run v run example.v

What did you expect to see?
[[1, 2, 3]]

What did you see instead?

V panic: get_type_symbol: invalid type (typ=0 idx=0). Compiler bug. This should never happen. Please create a GitHub issue.

0   v                                   0x0000000107734ea0 v__table__Table_get_type_symbol + 128
1   v                                   0x00000001077b86ae v__gen__Gen_cc_type + 62
2   v                                   0x00000001077b8245 v__gen__Gen_base_type + 69
3   v                                   0x000000010779fb1b v__gen__Gen_typ + 27
4   v                                   0x00000001077ab10b v__gen__Gen_gen_str_for_array + 123
5   v                                   0x00000001077aa51a v__gen__Gen_gen_str_for_type + 938
6   v                                   0x00000001077ab387 v__gen__Gen_gen_str_for_array + 759
7   v                                   0x00000001077aa51a v__gen__Gen_gen_str_for_type + 938
8   v                                   0x00000001077ca9f1 v__gen__Gen_gen_expr_to_string + 1201
9   v                                   0x00000001077da83d v__gen__Gen_string_inter_literal + 3437
10  v                                   0x00000001077a246d v__gen__Gen_expr + 9853
11  v                                   0x00000001077e8e22 v__gen__Gen_call_args + 1634
12  v                                   0x00000001077e8751 v__gen__Gen_fn_call + 4753
13  v                                   0x00000001077ce7db v__gen__Gen_call_expr + 1131
14  v                                   0x000000010779ffe5 v__gen__Gen_expr + 501
15  v                                   0x00000001077ba293 v__gen__Gen_stmt + 2595
16  v                                   0x00000001077b959b v__gen__Gen_stmts_with_tmp_var + 363
17  v                                   0x00000001077b3ae3 v__gen__Gen_stmts + 83
18  v                                   0x00000001077c3501 v__gen__Gen_gen_fn_decl + 6001
19  v                                   0x00000001077ba883 v__gen__Gen_stmt + 4115
20  v                                   0x00000001077b959b v__gen__Gen_stmts_with_tmp_var + 363
21  v                                   0x00000001077b3ae3 v__gen__Gen_stmts + 83
22  v                                   0x00000001077b1be1 v__gen__cgen + 4529
23  v                                   0x0000000107804805 v__builder__Builder_gen_c + 549
24  v                                   0x0000000107804ed7 v__builder__Builder_build_c + 295
25  v                                   0x00000001078052de v__builder__Builder_compile_c + 846
26  v                                   0x000000010780ffb3 v__builder__compile + 339
27  v                                   0x0000000107814777 main__main + 4359
28  v                                   0x0000000107816d7e main + 78
29  v                                   0x00000001076dc754 start + 52
30  ???                                 0x0000000000000003 0x0 + 3
@natemcintosh
Copy link
Author

It seems like the issue has changed, but that there still is an issue.

v doctor gives

$ v doctor
OS: macos, Mac OS X, 10.15.6, 19G2531
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
CC version: Apple clang version 12.0.0 (clang-1200.0.32.28)

getwd: /Users/natemcintosh/Documents/dev/vtesting
vmodules: /Users/natemcintosh/.vmodules
vroot: /Users/natemcintosh/Documents/dev/v
vexe: /Users/natemcintosh/Documents/dev/v/v
vexe mtime: 2021-01-06 23:51:36
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.1 9593ad2

Git version: git version 2.24.3 (Apple Git-128)
Git vroot status: 0.2-330-g9593ad20
.git/config present: true
thirdparty/tcc status: thirdparty-macos-amd64 689c8a02

What did you do?

// testing.v
fn main() {
	d11 := [1, 2, 3]
	d12 := example(d11)
	println('$d11 -> $d12')
	d21 := [1., 2., 3.]
	d22 := example(d21)
	println('$d21 -> $d22')
	d31 := ['hello', 'my', 'name', 'is']
	d32 := example(d31)
	println('$d31 -> $d32')
}

fn example<T>(data []T) [][]T {
	return [data]
}

and at the command line v run testing.v

What did you expect to see?

[1, 2, 3] -> [[1, 2, 3]]
[1, 2, 3] -> [[1, 2, 3]]
['hello', 'my', 'name', 'is'] -> [['hello', 'my', 'name', 'is']]

What did you see instead?

[1, 2, 3] -> [4]
[1, 2, 3] -> [1.39071e-309]
Terminated by signal 11 (SIGSEGV)

@natemcintosh
Copy link
Author

This no longer seems to be an issue

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.
Projects
None yet
Development

No branches or pull requests

1 participant