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

nested expression is treaded as invalid when trying to call a method on it #20976

Open
ttytm opened this issue Mar 8, 2024 · 0 comments
Open
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@ttytm
Copy link
Member

ttytm commented Mar 8, 2024

Describe the bug

Currently, it's not possible to directly call a method on an expression inside another expression. It is required to assign the nested expression to a variable and call it on a variable.

Reproduction Steps

str_from_nested_exp := if true {
	'foo'
} else {
	if true { 'foo.bar' } else { 'foo.bar.baz' }.all_after('foo.')
}

Expected Behavior

Works without additional assignment.

Current Behavior

bugs/nested_exp.v:4:47: error: cannot call a method using an invalid expression
    2 |     'foo'
    3 | } else {
    4 |     if true { 'foo.bar' } else { 'foo.bar.baz' }.all_after('foo.')
      |                                                  ~~~~~~~~~~~~~~~~~
    5 | }

Requires workaround, behaviour seems inconsistent (e.g. an expression without additional assignment works as function return).

str_from_nested_exp := if true {
	'foo'
} else {
	// Assigning the expression to a variable works.
	b := if true { 'foo.bar' } else { 'foo.bar.baz' }.all_after('foo.')
	b
}

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.4

Environment details (OS name and version, etc.)

OS: macos, macOS, 14.2.1, 23C71
Processor: 8 cpus, 64bit, little endian, Apple M1

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.

@ttytm ttytm added the Bug This tag is applied to issues which reports bugs. label Mar 8, 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.
Projects
None yet
Development

No branches or pull requests

1 participant