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

Empty interface array push fixed array C error #23011

Open
jorgeluismireles opened this issue Nov 30, 2024 · 2 comments
Open

Empty interface array push fixed array C error #23011

jorgeluismireles opened this issue Nov 30, 2024 · 2 comments
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.

Comments

@jorgeluismireles
Copy link

jorgeluismireles commented Nov 30, 2024

Describe the bug

We push a fixed array to an array of empty interfaces and got a C error.

Reproduction Steps

interface Any { }

fn main() {
	mut i := []int{}
	i << [1,2]  // accepted
	//i << [3,4]! // compiler return error correctly
	dump('${i}')
	mut a := []Any{}
	a << [5,6]     // accepted
	a << ['a','b'] // accepted
	a << [7,8]!    // compiler FAILS
	dump('${a}')
}

Expected Behavior

Prevent compiling line a << [7,8]! and notify user like with regular arrays (line i << [3,4]!).

Current Behavior

Running code...
Can't run code. The server returned an error:
/tmp/v_60000/code.01JDXEW5Z77GQRH940K6HWSHM6.tmp.c:1024: error: ';' expected (got "Array_fixed_main__Any_2")
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 .
Exited with error status 1
Please try again.

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 f2c281e

Environment details (OS name and version, etc.)

https://play.vlang.io/p/d6f2c96b61

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.

Huly®: V_0.6-21452

@jorgeluismireles jorgeluismireles added the Bug This tag is applied to issues which reports bugs. label Nov 30, 2024
@felipensp
Copy link
Member

Why prevent to use it? It seems a valid V code.

@felipensp felipensp added 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. labels Dec 11, 2024
@jorgeluismireles
Copy link
Author

Why prevent to use it? It seems a valid V code.

I think you are right. At first I though no array should accept a fixed array, but since next case works:

fn main() {
	mut i := [][2]string{}
	i << ['a','b']!
	i << [['c','d']!, ['e','f']!]
	assert i.str() == "[['a', 'b'], ['c', 'd'], ['e', 'f']]"
}

Then should be accepted this:

interface Any {}
fn main() {
	mut a := []Any{}
	a << ['a','b']! // should be accepted after fixing C error
}

Event though, I don't know what to expect. It should be one or another:

assert a.str() == "[Any('a'), Any('b')]"
assert a.str() == "[Any(['a','b'])]"

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

No branches or pull requests

2 participants