Skip to content

checker: wrong method check for array and array of options #24423

@enghitalo

Description

@enghitalo

Describe the bug

decode_array think that []?int is []int

Reproduction Steps

struct Decoder { }

pub fn decode[T](val string) !T {
	mut decoder := Decoder{}
	mut result := T{}
	decoder.decode_value(mut result)!
	return result
}

fn (mut decoder Decoder) decode_value[T](mut val T) ! {
	$if T.unaliased_typ is $array {
		// checking wrongly. `decode_array` think that `[]?int` is `[]int`
		decoder.decode_array(mut val)!
		return
	} $else $if T.unaliased_typ is $struct {
		$for field in T.fields {
			decoder.decode_value(mut val.$(field.name))!
		}
	}
}

fn (mut decoder Decoder) decode_array[T](mut val []T) ! {}

struct Foo {
	int  []int
	oint []?int
}

fn main() {
	decode[Foo]('')!
}

Expected Behavior

Not error

Current Behavior

code.v:13:27: error: cannot use `&[]?int` as `&[]int` in argument 1 to `Decoder.decode_array`
   11 |     $if T.unaliased_typ is $array {
   12 |         // checking wrongly
   13 |         decoder.decode_array(mut val)!
      |                                 ~~~
   14 |         return
   15 |     } $else $if T.unaliased_typ is $struct {

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.10 d9afebc

Environment details (OS name and version, etc.)

Ubuntu

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.

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.Generics[T]Bugs/feature requests, that are related to the V generics.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.Unit: CheckerBugs/feature requests, that are related to the type checker.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions