Skip to content

ast: proposed fix for list of generic bug#27127

Open
kimshrier wants to merge 1 commit intovlang:masterfrom
kimshrier:generic-list-fix
Open

ast: proposed fix for list of generic bug#27127
kimshrier wants to merge 1 commit intovlang:masterfrom
kimshrier:generic-list-fix

Conversation

@kimshrier
Copy link
Copy Markdown
Contributor

I ran in to another code generation bug while I was playing around with generics.

The following code shows the problem:

module main

struct Container[T] {}

pub fn (c Container[T]) get() !T {
	return T{}
}

fn make_list[T]() Container[[]T] {
	return Container[[]T]{}
}

fn test_make_list() {
	_ := make_list[int]()
	assert true
}

Prior to making the change, I would see the following error:

$ v test /private/tmp/generic_method_slice_test.v
---- Testing... ------------------------------------------------------------------------------------
/private/tmp/generic_method_slice_test.v:6:9: error: cannot use `[][][]T` as type `![][]T` in return argument
    4 | 
    5 | pub fn (c Container[T]) get() !T {
    6 |     return T{}
      |            ~~~
    7 | }
    8 |
 FAIL     0.000 ms /private/tmp/generic_method_slice_test.v
>> compilation failed:
/private/tmp/generic_method_slice_test.v:6:9: error: cannot use `[][][]T` as type `![][]T` in return argument
    4 | 
    5 | pub fn (c Container[T]) get() !T {
    6 |     return T{}
      |            ~~~
    7 | }
    8 |

----------------------------------------------------------------------------------------------------
To reproduce just failure 1 run:    '/Users/kim/Projects/v/from_github/v/v'  '/private/tmp/generic_method_slice_test.v'
Summary for all V _test.v files: 1 failed, 1 total. Elapsed time: 846 ms, on 1 job. Comptime: 792 ms. Runtime: 0 ms.

After applying the change, the error goes away:

$ v test /private/tmp/generic_method_slice_test.v
---- Testing... ------------------------------------------------------------------------------------
 OK     406.864 ms /private/tmp/generic_method_slice_test.v
----------------------------------------------------------------------------------------------------
Summary for all V _test.v files: 1 passed, 1 total. Elapsed time: 713 ms, on 1 job. Comptime: 305 ms. Runtime: 406 ms.
$ v doctor
|V full version      |V 0.5.1 ed5fc1638abe439f5b4d5d31e0c91a81af065b94
|:-------------------|:-------------------
|OS                  |macos, macOS, 26.4.1, 25E253
|Processor           |10 cpus, 64bit, little endian, Apple M1 Max
|Memory              |1.3GB/64GB
|                    |
|V executable        |/Users/kim/Projects/v/from_github/v/v
|V last modified time|2026-05-10 21:34:03
|                    |
|V home dir          |OK, value: /Users/kim/Projects/v/from_github/v
|VMODULES            |OK, value: /Users/kim/.vmodules
|VTMP                |OK, value: /tmp/v_1002
|Current working dir |OK, value: /Users/kim/Projects/Github/v
|                    |
|env LDFLAGS         |"-L/opt/homebrew/opt/postgresql@15/lib"
|Git version         |git version 2.50.1 (Apple Git-155)
|V git status        |0.5.1-1536-ged5fc163-dirty
|.git/config present |true
|                    |
|cc version          |Apple clang version 21.0.0 (clang-2100.0.123.102)
|gcc version         |Apple clang version 21.0.0 (clang-2100.0.123.102)
|clang version       |Apple clang version 21.0.0 (clang-2100.0.123.102)
|tcc version         |tcc version 0.9.28rc 2026-01-10 HEAD@5ec0e6f8 (AArch64 Darwin)
|tcc git status      |thirdparty-macos-arm64 f995efa3
|emcc version        |N/A
|glibc version       |N/A

@medvednikov
Copy link
Copy Markdown
Member

thanks, but needs a test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants