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

Comptime reflection compares all field values as strings. #19566

Closed
katekyy opened this issue Oct 14, 2023 · 0 comments · Fixed by #19691
Closed

Comptime reflection compares all field values as strings. #19566

katekyy opened this issue Oct 14, 2023 · 0 comments · Fixed by #19691
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Build V build error on any OS/CPU architecture. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@katekyy
Copy link
Contributor

katekyy commented Oct 14, 2023

Describe the bug

As said in the title, compile time reflection compares all field values as strings.
Looking at the generated C code:

if (!string__eq(_v_new.ButtonStyleParams, _v_default.ButtonStyleParams)) {
	old->ButtonStyleParams = _v_new.ButtonStyleParams;
}

Reproduction Steps

struct Abc {
	id int
	name string
	letter string
}

fn join[T](mut old T, new T) {
	$if T is $struct {
		default := T{}
		$for field in T.fields {
			if new.$(field.name) != default.$(field.name) {
				old.$(field.name) = new.$(field.name)
			}
		}
	}
}

fn main() {
	mut a := Abc{name: 'Peter', letter: 'a'}
	b := Abc{id: 1, letter: 'b'}
	join(mut a, b)

	assert a == Abc{name: 'Peter', id: 1, letter: 'b'}
}

Expected Behavior

Output:

Abc{
    id: 1
    name: 'Peter'
    letter: 'b'
}

Current Behavior

==================
/tmp/v_1000/zest_launcher.tmp.c:76124: warning: assignment from incompatible pointer type
/tmp/v_1000/zest_launcher.tmp.c:91043: error: cannot convert 'struct ui__ButtonStyleParams' to 'struct string'
...
==================
(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

Possible Solution

No response

Additional Information/Context

No response

V version

0.4.2 8f76a06

Environment details (OS name and version, etc.)

V full version: V 0.4.2 8f76a06
OS: linux, Linux version 6.1.52-1-lts (linux-lts@archlinux) (gcc (GCC) 13.2.1 20230801, GNU ld (GNU Binutils) 2.41.0) #1 SMP PREEMPT_DYNAMIC Thu, 07 Sep 2023 05:17:41 +0000
Processor: 8 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz

getwd: /home/katekyy/programming/zest_launcher
vexe: /home/katekyy/.local/share/v/v
vexe mtime: 2023-10-14 18:01:00

vroot: OK, value: /home/katekyy/.local/share/v
VMODULES: OK, value: /home/katekyy/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.42.0
Git vroot status: weekly.2023.33-352-g8f76a062
.git/config present: true

CC version: cc (GCC) 13.2.1 20230801
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

Note

You can vote for this issue using the 👍 reaction. More votes increase the issue's priority for developers.

Take into account that only the 👍 reaction counts as a vote.
Only reactions to the issue itself will be counted as votes, not comments.

@katekyy katekyy added the Bug This tag is applied to issues which reports bugs. label Oct 14, 2023
@ArtemkaKun ArtemkaKun added Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Build V build error on any OS/CPU architecture. labels Oct 14, 2023
@felipensp felipensp self-assigned this Oct 28, 2023
@felipensp felipensp changed the title Reflection compares all field values as strings. Comptime reflection compares all field values as strings. Oct 28, 2023
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. Build V build error on any OS/CPU architecture. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants