internal/core/export: fix panic in relPathLength for BinaryExpr
Extracting a sub-expression with nested (Def & {...}).field
patterns across package boundaries panics in relPathLength
with "unreachable" because SelectorExpr.X can be a BinaryExpr,
which is not handled.
We need to apply two fixes to resolve the panic:
1. In relPathLength, a BinaryExpr (or any non-Resolver) as the base of
a selector chain is a valid end-of-chain. Return (length, false)
instead of panicking.
2. In completePivot, use a fixpoint loop instead of a single pass.
Exporting one external's body (in addExternal) may set needTopLevel
on deps that appear earlier in the list. Without the fixpoint loop,
those deps are never hoisted as let bindings.
Note that the added testdata file reproduces the panic without the fix,
so we must add the test alongside the fix in one commit.
Fixes #4237.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ie93ad75a3504c633c92f9d9315e77ab7ca09e89f
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1231150
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>