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

checker: cannot assign to *val: expected StructTypePointer[int], not int literal #23020

Open
enghitalo opened this issue Nov 30, 2024 · 0 comments
Labels
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.

Comments

@enghitalo
Copy link
Contributor

enghitalo commented Nov 30, 2024

Describe the bug

perhaps generics methods is build problem?

Reproduction Steps

struct Decoder {}

struct StructTypePointer[T] {
mut:
	val &T
}

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.indirections != 0 {
		unsafe {
			*val = 2
		}
	} $else $if T is $struct {
		decode_value(mut val.val)!
	}
}

fn main() {
	assert *decode[StructTypePointer[int]]('2')!.val == 2
}

Expected Behavior

assert pass

Current Behavior

bug.v:19:11: error: cannot assign to `*val`: expected `StructTypePointer[int]`, not `int literal`
   17 |     $if T.indirections != 0 {
   18 |         unsafe {
   19 |             *val = 2
      |                    ^
   20 |         }
   21 |     } $else $if T is $struct {
bug.v:22:3: error: unknown function: decode_value
   20 |         }
   21 |     } $else $if T is $struct {
   22 |         decode_value(mut val.val)!
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~
   23 |     }
   24 | }
bug.v:22:28: error: unexpected `!`, the function `decode_value` does not return a Result
   20 |         }
   21 |     } $else $if T is $struct {
   22 |         decode_value(mut val.val)!
      |                                  ^
   23 |     }
   24 | }
If the code of your project is in multiple files, try with `v .` instead of `v bug.v`

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 602b097

Environment details (OS name and version, etc.)

Linux

Huly®: V_0.6-21461

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.

@enghitalo enghitalo added the Bug This tag is applied to issues which reports bugs. label Nov 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. labels Dec 1, 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. Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

No branches or pull requests

2 participants