dark
dark copied to clipboard
(Fluid) Reconstructing list/tuples can cause "zeroes" to be mistakenly inserted
- Create a REPL of code:
let z = [1,2,3] - highlight
,2, - create a new line below the
let - paste
I expect either 2 or [ _ , 2, _ ] as the result, but instead get [0,2,0].
Similarly, if we replace 2 with "test", we get ["", "test", ""] as the result.
Tuples are likely to have this bug as well shortly as of #4182, unless we resolve this Issue prior to that merging.
@pbiggar do you have any intuition as to when this condition could be hit? For some reason, the code+comment just isn't making sense to me.
What are examples of "tokens that don't have ancestors (depth = 0) but are not the topmost expression in the AST"?
Relevantly, a .minByWithIndex could intuitively be used rather than this .fold (which would improve clarity a lot), but this mystery condition may prevent that from realistically happening.
I've stumbled upon a fix for this while working on #4452 - the result is that these steps:
- Create a REPL of code:
let z = [1,2,3] - highlight
,2, - create a new line below the
let - paste
result in [_,2,_] being reconstructed. Before changes, it resulted in [0,2,0] (bad).
This seems appropriate to me; the only other option I'd understand would be for this to result in 2, which seems worse.
Does this outcome seem ideal to you, @pbiggar?
Yeah, this seems right