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

Possible struct def overwritten in generated C code. #21746

Open
txgruppi opened this issue Jun 27, 2024 · 0 comments
Open

Possible struct def overwritten in generated C code. #21746

txgruppi opened this issue Jun 27, 2024 · 0 comments

Comments

@txgruppi
Copy link
Contributor

txgruppi commented Jun 27, 2024

V doctor:

V full version: V 0.4.6 58a8fc6.fccd7cd
OS: linux, Pop!_OS 22.04 LTS
Processor: 16 cpus, 64bit, little endian, AMD Ryzen 7 2700X Eight-Core Processor

getwd: /home/txgruppi/src/REDACTED
vexe: /home/txgruppi/src/github.com/vlang/v/v
vexe mtime: 2024-06-27 15:09:16

vroot: OK, value: /home/txgruppi/src/github.com/vlang/v
VMODULES: OK, value: /home/txgruppi/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.34.1
Git vroot status: weekly.2024.26-11-gfccd7cd0
.git/config present: true

CC version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
thirdparty/tcc status: thirdparty-linux-amd64 40e5cbb5

What did you do?
v -g -o vdbg cmd/v && vdbg docker-login-fix.vsh

#!/usr/bin/env -S v run

import datatypes

struct GitlabCI {
	path    string
	content string
}

fn walker(root string) chan string {
	ch_out := chan string{}

	f := fn (ch_out chan string, root string) ! {
		mut stack := datatypes.Stack[string]{}
		stack.push(root)

		ignore_list := ['.git', 'node_modules']

		for !stack.is_empty() {
			curr := stack.pop()!
			for child in ls(curr)! {
				if child in ignore_list {
					continue
				}
				childpath := join_path(curr, child)
				if is_dir(childpath) {
					stack.push(childpath)
					continue
				}
				if !child.starts_with('.gitlab-ci.') {
					continue
				}
				ch_out <- childpath
			}
		}
		ch_out.close()
	}

	spawn f(ch_out, root)

	return ch_out
}

fn loader(ch_in chan string) chan GitlabCI {
	ch_out := chan GitlabCI{}

	f := fn (ch_in chan string, ch_out chan GitlabCI) ! {
		for next := true; next; {
			next = select {
				chidlpath := <-ch_in {}
			}
		}
		ch_out.close()
	}

	spawn f(ch_in, ch_out)

	return ch_out
}

ch0 := walker(getwd())
ch1 := loader(ch0)

println(ch1)

What did you expect to see?

chan GitlabCI{cap: 0, closed: 0}

What did you see instead?

docker-login-fix.vsh:50:5: warning: unused variable: `chidlpath`
   48 |         for next := true; next; {
   49 |             next = select {
   50 |                 chidlpath := <-ch_in {}
      |                 ~~~~~~~~~
   51 |             }
   52 |         }
==================
/tmp/v_1000/docker-login-fix.01J1D3X67FYSHQAN9PYWR4T64X.tmp.c:24985: warning: assignment from incompatible pointer type
/tmp/v_1000/docker-login-fix.01J1D3X67FYSHQAN9PYWR4T64X.tmp.c:24987: error: cannot convert 'struct sync__Channel *' to 'struct string'
...
==================
(Use `v -cg` to print the entire error message)

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 .

Maybe helpful information

It looks like the issue is because of the f function inside walker and loader and the generated C code has the thread_arg_f definition overwritten because of the other function with the same name.

If I change the name of one of the f functions to ff, for example, the code works 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant