zed
zed copied to clipboard
Inform user of failed spread operations
tl;dr
A user asked in a community Slack thread:
Here's sort of a related situation I just ran across. Using the spread operator with a mismatch of array or record:
❯ zq 'yield [1,2] | {...this, ...{b:2}}' {b:2}
It'd be nice if there was a warning somehow - I don't mind that it sort of rolls on through rather than injecting an error object I suppose ... but ... not sure. Not having any feedback on my mistake (which can be more opaque in real contexts) is a bit frustrating.
Details
Repro is with Zed commit 6b4afe5. This issue came from the same user that floated #5176 and it's somewhat similar in spirit.
FWIW, the docs do disclose this, e.g., in the section on record expressions:
If a spread expression results in a non-record type (e.g., errors), then that part of the record is simply elided.
However, it's understandable how a user still learning the language and attempting to use spread for the first time would find this "silently do nothing" behavior vexing and leave them short of ideas of where to turn (hence the inquiry on Slack).
Since the Zed is compiling and running ok, at the spot where our code it's currently skipping over the unworkable ...this
spread, we could instead surface some kind of notification to better describe the nature of the failure. As @mccanne pointed out, this is part of a wider effort where we need to make better use of the mechanisms we have for surfacing warnings/errors, making it possible to silence them when a user doesn't want to see them, redirect them when desired, etc.