Closed ghalle closed 9 years ago
maybe we could make Reflect.setField
return a value...
I took a quick look at it and it seems that:
object[name] = value
.$object->{$name} = $value
- does it return a value? cc @fponticellisetattr
doesn't return a value unfortunately, so we probably want to think of something here. cc @frabbit I would prefer if we didn't change Reflect.setField
. The main purpose of setters returning values is to chain them, which is not something you typically do when using Reflect. It's better to implement this on the syntax side of things, i.e. DynamicAccess.set
.
Agree with @Simn. And let the code optimizer get rid of the unused statement as it should
I changed DynamicAccess.set
to return given value and added an optimized version for JavaScript that doesn't generate extra vars and closures. That looks good enough for now.
Chain assignment like this won't work with the error: "Arguments and variables of type Void are not allowed"
That is because the set function return void:
Ideally I would return the setField call but setField return Void and not the value set. I tried this workaround:
But it is not ideal as it create 2 separate statement and with complex assignment this creates multiple variables and statements.