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

compiler bug: compiler confused by function called vbytes() calling array.vbytes() #12610

Closed
thomas-mangin opened this issue Nov 29, 2021 · 5 comments · Fixed by #22291
Closed
Assignees
Labels
Bug This tag is applied to issues which reports bugs. 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.

Comments

@thomas-mangin
Copy link
Contributor

V doctor:

OS: macos, macOS, 12.0.1, 21A559
Processor: 10 cpus, 64bit, little endian, Apple M1 Max
CC version: Apple clang version 13.0.0 (clang-1300.0.29.3)

getwd: /Users/thomas/bug
vmodules: /Users/thomas/.vmodules
vroot: /Users/thomas/Unix/v-latest
vexe: /Users/thomas/Unix/v-latest/v
vexe mtime: 2021-11-29 09:04:46
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.4 24ba660.c14c324

Git version: git version 2.34.0
Git vroot status: weekly.2021.47-49-gc14c3241
.git/config present: true
thirdparty/tcc status: thirdparty-macos-amd64 689c8a02

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

type Buffer = []byte

pub fn (mut sb Buffer) vbytes() string {
	return sb[0..sb.len].vbytes().str()
}

fn main() {
	mut b := Buffer([]byte{cap:10})
	b << 1
	b << 2
	println(b.vbytes())
}

What did you expect to see?

no crash

What did you see instead?

==================
       ^
/tmp/v_501/bug.10506693758119739925.tmp.c:10602:26: error: passing 'int' to parameter of incompatible type 'string' (aka 'struct string')
        string _t1 = string_str(main__Buffer_vbytes_static(array_slice(*sb, 0, sb->len)));
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/v_501/bug.10506693758119739925.tmp.c:9362:26: note: passing argument to parameter 's' here
string string_str(string s) {
                         ^
2 errors 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

@medvednikov medvednikov added the Bug This tag is applied to issues which reports bugs. label Jul 19, 2022
@felipensp felipensp self-assigned this Sep 23, 2024
@felipensp
Copy link
Member

sb[0..sb.len].vbytes() does the code generate recursive call to Buffer.vbytes()

@felipensp felipensp removed their assignment Sep 24, 2024
@felipensp
Copy link
Member

felipensp commented Sep 24, 2024

&u8 and voidptr does implements vbytes(), not byte. What do you think @medvednikov @spytheman ?

@felipensp felipensp added Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Sep 24, 2024
@JalonSolov
Copy link
Contributor

byte is an alias for u8 now, and it is also deprecated. Since it is deprecated, I don't see any reason to make this work for byte type.

However, even changing byte to u8 in the example, there is still an error:

/tmp/v_1000/../../../../../../home/jalon/x.v:4: warning: implicit declaration of function 'main__Buffer_vbytes_static'
/tmp/v_1000/../../../../../../home/jalon/x.v:4: error: cannot convert 'int' to 'struct string'

The line in question is

	return sb[0..sb.len].vbytes().str()

@felipensp
Copy link
Member

byte is an alias for u8 now, and it is also deprecated. Since it is deprecated, I don't see any reason to make this work for byte type.

However, even changing byte to u8 in the example, there is still an error:

/tmp/v_1000/../../../../../../home/jalon/x.v:4: warning: implicit declaration of function 'main__Buffer_vbytes_static'
/tmp/v_1000/../../../../../../home/jalon/x.v:4: error: cannot convert 'int' to 'struct string'

The line in question is

	return sb[0..sb.len].vbytes().str()

Yes. This failure is being treated in another PR which I have submitted.

@felipensp felipensp self-assigned this Sep 24, 2024
@felipensp
Copy link
Member

string _t1 = string_str(byteptr_vbytes(&array_slice(*sb, 0, sb->len)));

cc: /tmp/v_1000/bug.01J8GVC9EWGNTR2VFHP39SKJHC.tmp.c:13334: warning: assignment from incompatible pointer type
cc: /tmp/v_1000/bug.01J8GVC9EWGNTR2VFHP39SKJHC.tmp.c:13334: error: too few arguments to function

We must fix this case... since byteptr_vbytes has 2 params.

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

Successfully merging a pull request may close this issue.

4 participants