Compilation failures caused by code from previous sketch after "Save As"

Continuing the discussion from Arduino IDE "Save As" Doesn't Change Editor:

I'm having the same problem. Something is amiss with save as. It can do some really weird things. As you have stated I also use the "save as" to start a new program. Ny problem goes a bit deeper. When programming an esp32 yesterday afternoon I had used the save as to copy some existing known good code as a starting point. Add a couple of print statement to the code, hit the compile button and I get a missing "h" file error from the compiler. no big deal - add the file and hit the compile again. Get a new missing "h" file from the compiler. This time I wake up and really look into whats going on. The compiler error has nothing to do with the current code. Not reference anywhere. Hmmm... then the light comes on - but it was referenced in code I was running in a previous edit session using a different piece of code. I decided to go along with the compiler to get all the "h" files it wanted. Then I get the " collect2.exe: error: ld returned 1" error. So I immediately delete the appdata...core files. Problem goes away!!
Start the whole process over this time letting the IDE create a new sketch. Copy/paste the wanted code into the newly created sketch and this time I have no issues. Edit the rest of the afternoon with no issues.
This is not the first time I have seen this. Just the first time
I was able to understand that there is a unwanted feature in the "save as" function. I now avoid using save as and things seem to be working as expected.

Hi @ravenable. Can you provide a detailed set of step-by-step minimal instructions we can follow to reproduce the fault?

It sounds somewhat like this known bug:

However, that is not known to be caused by a "Save As..." operation, so I'm not certain.