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

Generics: Passing an array of generic type without type annotation causes C error #23315

Closed
syobocat opened this issue Dec 30, 2024 · 0 comments · Fixed by #23322
Closed

Generics: Passing an array of generic type without type annotation causes C error #23315

syobocat opened this issue Dec 30, 2024 · 0 comments · Fixed by #23322
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@syobocat
Copy link
Contributor

syobocat commented Dec 30, 2024

Describe the bug

Passing an array that generic function returns to other generic function, it causes C error

Reproduction Steps

fn function_that_receives_an_array_of_generic_type[T](array []T) {
	return
}

fn function_that_returns_an_array_of_generic_type[T]() []T {
	return []
}

fn func[T]() {
	res := function_that_returns_an_array_of_generic_type[T]()
	function_that_receives_an_array_of_generic_type(res)
	return
}

fn main() {
	func[string]()
}

Expected Behavior

Successful compilation, or a V error

Current Behavior

======== Output of the C Compiler (cc) ========
/tmp/v_501/code.01JGBDZRRD9V6ZGP0VAJJZJW53.tmp.c:1315:91: error: unknown type name 'Array_Array_string'; did you mean 'Array_string'?
 1315 | VV_LOCAL_SYMBOL void main__function_that_receives_an_array_of_generic_type_T_Array_string(Array_Array_string __v_array);
      |                                                                                           ^~~~~~~~~~~~~~~~~~
      |                                                                                           Array_string
/tmp/v_501/code.01JGBDZRRD9V6ZGP0VAJJZJW53.tmp.c:778:15: note: 'Array_string' declared here
  778 | typedef array Array_string;
      |               ^
/tmp/v_501/code.01JGBDZRRD9V6ZGP0VAJJZJW53.tmp.c:5559:91: error: unknown type name 'Array_Array_string'; did you mean 'Array_string'?
 5559 | VV_LOCAL_SYMBOL void main__function_that_receives_an_array_of_generic_type_T_Array_string(Array_Array_string __v_array) {
      |                                                                                           ^~~~~~~~~~~~~~~~~~
      |                                                                                           Array_string
/tmp/v_501/code.01JGBDZRRD9V6ZGP0VAJJZJW53.tmp.c:778:15: note: 'Array_string' declared here
  778 | typedef array Array_string;
      |               ^
2 errors generated.
===============================================

Possible Solution

No response

Additional Information/Context

It compiles successfully when you add type annotation:

fn function_that_receives_an_array_of_generic_type[T](array []T) {
	return
}

fn function_that_returns_an_array_of_generic_type[T]() []T {
	return []
}

fn func[T]() {
	res := function_that_returns_an_array_of_generic_type[T]()
-	function_that_receives_an_array_of_generic_type(res)
+	function_that_receives_an_array_of_generic_type[T](res)
	return
}

fn main() {
	func[string]()
}

V version

V 0.4.9 fb5bac1

Environment details (OS name and version, etc.)

V full version: V 0.4.9 c4aaa2e.fb5bac1
OS: macos, macOS, 15.2, 24C101
Processor: 8 cpus, 64bit, little endian, Apple M3

getwd: /Users/syobon
vexe: /Users/syobon/.v/v
vexe mtime: 2024-12-30 09:17:55

vroot: OK, value: /Users/syobon/.v
VMODULES: OK, value: /Users/syobon/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.39.5 (Apple Git-154)
Git vroot status: 0.4.9-55-gfb5bac11
.git/config present: true

CC version: Apple clang version 16.0.0 (clang-1600.0.26.6)
emcc version: N/A
thirdparty/tcc status: thirdparty-macos-arm64 713692d4

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-21747

@syobocat syobocat added the Bug This tag is applied to issues which reports bugs. label Dec 30, 2024
@felipensp felipensp self-assigned this Dec 30, 2024
@felipensp felipensp added Generics[T] Bugs/feature requests, that are related to the V generics. Unit: Checker Bugs/feature requests, that are related to the type checker. Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. and removed Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: Checker Bugs/feature requests, that are related to the type checker. labels Dec 30, 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. Generics[T] Bugs/feature requests, that are related to the V generics. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants