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

bug overload operator when type is generic #20777

Closed
Ddiidev opened this issue Feb 10, 2024 · 0 comments · Fixed by #20795
Closed

bug overload operator when type is generic #20777

Ddiidev opened this issue Feb 10, 2024 · 0 comments · Fixed by #20795
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.

Comments

@Ddiidev
Copy link
Contributor

Ddiidev commented Feb 10, 2024

Describe the bug

Code: https://play.vlang.io/p/7bb26503ba

import time

struct SubTestTimeOptional[T] {
	iis string
	ext T
}

pub fn (s1 SubTestTimeOptional[T]) == (s2 SubTestTimeOptional[T]) bool {
	return s1.iis == s2.iis
}

struct TestTimeOptional {
	exp ?time.Time
}

fn now_optional[T]() SubTestTimeOptional[T] {
	return SubTestTimeOptional[TestTimeOptional] {
		iis: "asdadwq123"
		ext: TestTimeOptional{
			exp: time.now()
		}
	}
}

fn now_delay_optional[T]() SubTestTimeOptional[T] {
	return SubTestTimeOptional[T] {
		iis: "asdadwq123"
		ext: TestTimeOptional{
			exp: time.now().add_seconds(5)
		}
	}
}

mut  t1 := now_optional[TestTimeOptional]()
mut t2 := now_delay_optional[TestTimeOptional]()

assert t1 == t2

Reproduction Steps

▶️ play.vlang

Expected Behavior

result: true

Current Behavior

Output:

/tmp/v_60000/code.01HP9Z09B4N624H9AAX2RGCBNA.tmp.c:2574: warning: implicit declaration of function '_option_time__Time__eq'
tcc: error: undefined symbol '_option_time__Time__eq'
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

Exited with error status 1

Possible Solution

No response

Additional Information/Context

See that it reports that it is not defined compared to the optional Timer type.
But that's not the problem, since in my == operator overload I'm not using the exp ?time.Time field.

the original code is:

pub fn (s1 SubTestTimeOptional[T]) == (s2 SubTestTimeOptional[T]) bool {
	return s1.iis == s2.iis
}

If you change/add this section, everything works beautifully.

pub fn (s1 SubTestTimeOptional[TestTimeOptional]) == (s2 SubTestTimeOptional[TestTimeOptional]) bool {
	return s1.iis == s2.iis
}

V version

V 0.4.4 212adfa

Environment details (OS name and version, etc.)

V full version: V 0.4.4 212adfa
OS: linux, Debian GNU/Linux 11 (bullseye) (VM)
Processor: 1 cpus, 64bit, little endian, Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz

getwd: /home/admin/playground
vexe: /home/admin/v/v
vexe mtime: 2024-02-10 16:23:23

vroot: OK, value: /home/admin/v
VMODULES: OK, value: .vmodules
VTMP: OK, value: /tmp/v_0

Git version: git version 2.30.2
Git vroot status: Error: fatal: detected dubious ownership in repository at '/home/admin/v'
To add an exception for this directory, call:

	git config --global --add safe.directory /home/admin/v
.git/config present: true

CC version: cc (Debian 10.2.1-6) 10.2.1 20210110
thirdparty/tcc status: Error: fatal: detected dubious ownership in repository at '/home/admin/v/thirdparty/tcc'
To add an exception for this directory, call:

	git config --global --add safe.directory /home/admin/v/thirdparty/tcc
 Error: fatal: detected dubious ownership in repository at '/home/admin/v/thirdparty/tcc'
To add an exception for this directory, call:

	git config --global --add safe.directory /home/admin/v/thirdparty/tcc

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.

@Ddiidev Ddiidev added the Bug This tag is applied to issues which reports bugs. label Feb 10, 2024
@Ddiidev Ddiidev changed the title bug overload type generic bug overload operator when type is generic Feb 10, 2024
@felipensp felipensp added the Unit: cgen Bugs/feature requests, that are related to the default C generating backend. label Feb 11, 2024
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants