-
Notifications
You must be signed in to change notification settings - Fork 312
trim issues after upgrade from v0.8.2 to v0.9.0 #3206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've tried to put together a re-producer, but I haven't been able to and I don't think it's a good idea to publicly make available the private cue bits. |
Oddly enough I changed our cue fmt makefile target to run and it runs fine (the mindepth there is due to the layout of the repo and how we use
|
@freeformz if you're unable to reduce the reproducer to be shared publicly, can you send it to me privately, for example via Slack? I can then do the reduction work so that we can have a small reproducer to investigate and add as a regression test. Without a reproducer it might be hard for us to investigate this bug properly, as you can imagine. |
@mvdan Thx. Sent via slack. |
@mvdan Can I help in any other way? |
Apologies for the slowness, @freeformz, I've been on holiday recently. @cuematthew and I have reduced the "unused import" error to this testscript:
Rather than succeeding as expected, by for example trimming the file or doing nothing at all, we get a confusing error like yours:
It's worth pointing out that CUE v0.8.2 failed in your code when running
Something changed between 0.8 and 0.9 where CUE now consistently shows the error, rather than inconsistently hiding it:
So it seems to us like the underlying "imported and not used" bug in trim already existed in v0.8, it was just being hidden from you when you ran |
We found the cause :) In your config, you had a list comprehension that always resulted in zero elements (
It's worth noting that, after the fix,
But you can use So, in short - CUE v0.8.2's From a quick look, the changes that |
@mvdan TY for the explanation and detailed break down! |
@mvdan I'm not sure how |
AFAICT I'm essentially doing this: https://cuelang.org/docs/tour/expressions/fieldcomp/
|
The Please ignore my mention of a list type mismatch - we spent a while aggressively reducing your code to reach the dozen lines of CUE I shared yesterday, and at some point during that process we made the list comprehension produce a list of strings rather than a list of structs. Your original code doesn't have this issue, as you correctly point out. The reproducer I shared ended up not having this issue either in the end, as we swapped |
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]>
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest stable release?
Yes - is new with v0.9.0 - not present in v0.8.2
What did you do?
But I am....
So I added
_what: strings.Split("what-the", "-")[0]
to the file ... and re-ran the trimMost, but not all of the
-
in the diff are for comprehensions....I am going to see if I can create a minimal re-producer, but don't have one yet.
What did you expect to see?
No change really ... this is an upgrade to v0.9.0 from a project that was using v0.8.2
What did you see instead?
See above.
The text was updated successfully, but these errors were encountered: