v icon indicating copy to clipboard operation
v copied to clipboard

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

Open ttytm opened this issue 1 year ago • 0 comments

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 avatar Mar 08 '24 06:03 ttytm