You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cue/ast/astutil: update ast.File.Imports properly in Sanitize
Sanitize removes unused imports from its input files, that is,
when a package is imported at the top of the file but not referenced.
Sanitize updated the ast.File.Decls list, which was OK for cue/format
to print out the file without the import, but it did not update
ast.File.Imports, which is a flattened list of import specs
used by the loader and the compiler.
As a sanity check, `cue trim` rebuilds each package instance it trims
before it writes the CUE files back to disk, to ensure it is not writing
invalid CUE which could cause confusing errors or data loss.
The rebuild then correctly failed with an "imported and not used" error.
Teach TestTrimFiles to catch the same mistake by rebuilding the files
as a new instance after the trimming has happened.
We already had a test which is meant to remove an unused import,
and since we didn't remove it properly per the above,
the rebuild tried and failed to load the imported package:
--- FAIL: TestTrimFiles/trim/rmimport (0.00s)
quicktest.go:12:
error:
got non-nil value
got:
e`package "mod.test/blah/a" not found`
Tweak Sanitize so that it keeps ast.File.Imports up to date.
ast.File holding all imports in both Decls and Imports is a bit of a
trap for any other user who wishes to add or remove any import,
so I've also raised #3324 to propose phasing out ast.File.Imports.
Updates #3206.
Signed-off-by: Daniel Martí <[email protected]>
Change-Id: I7552ffcba32f451842ea7fc0f39d71f0a365a13b
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1198351
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Matthew Sackman <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
0 commit comments