Xcode just added a bogus import statement to a source file by itself. WTH?

After a minor source-code change, my project wouldn't build anymore; Xcode raised dozens of errors complaining about a missing module and loads of other issues.

Lately Xcode (13.1) has been spewing spurious errors on a regular basis, highlighting allegedly erroneous source lines with repeated instances of the same complaint... but declaring 'build succeeded" in the status bar at the top of the screen and running the app successfully. This is happening on two systems, one Intel and the other Apple Silicon. I've not found any explanation. Cleaning and deleting DerivedData don't fix it.

So I've learned to ignore these "errors." But this time the build really was failing, so I looked at the first error. Xcode had inserted a line (into a years-old file) that attempted to import a nonexistent module. The name ("SwiftProtobufTests") appears in the package-definition file of a subproject (which builds Google protocol-buffer support in Swift). But it's not referred to or used anywhere, and I certainly didn't change anything in this source file related to it.

Has anybody else had this happen?

Xcode seems to have suffered from major regressions lately; it's barely stable enough to use right now. There are other insidious signs of internal problems. For example, when Xcode offers to "fix" an erroneous line (whether the error is real or not), it often inserts the fix into the wrong place in the text, garbling it and causing syntax errors.

It also inserts missing cases in switch statements (after the "must be exhaustive" error) at the wrong level in the hierarchy, also causing an error.

Again, this is happening on two systems, one a brand-new M1 Pro that was set up from scratch.