Description
Describe the bug
Earlier, I was refactoring some code and was in the process of changing the name of a variable for a dictionary. Before I changed one of the references to the variable, I received the following error message:
Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
I sometimes also see a Cannot find '<#name#>' in scope
error, but inconsistently between environments. The error could be resolved by changing the expression to use the updated name, but for a moment I was concerned I had a much more complicated error.
Steps To Reproduce
- Paste the following code into Xcode or an Xcode Playground (possibly only using Xcode 14 beta 3/the version of Swift it runs).
- Attempt to build (or run in an Xcode Playground).
- Check for described error message.
var newName: [Int : [Int]] = [:]
for (key, values) in oldName {
for (idx, value) in values.enumerated() {
print(key, idx, value)
}
}
...
Expected behavior
I expect to not see a Failed to produce diagnostic for expression
error for a simple unresolved name error.
Screenshots
Simplified Snippet in .playground
file
Simplified Snippet in .xcodeproj
Original-ish Snippet (preserves intent and observed error message) in .xcodeproj
While I'd usually appreciate the help, I do not need any comments on Swift best practices or correctness as this happened while I was refactoring someone else's code to ensure that it produces the intended result, is more readable, etc. Thanks for wanting to help though!
Environment (please fill out the following information)
- OS: macOS 12.4
- Xcode: Version 14.0 beta 3 (14A5270f)
Additional Context:
Original-ish code snippet in plain-text. Notes:
- there is a function parameter called
entityForRemoval
of typeEntity
- there is a class property called
committedEntities
(thecorrectName
in the simplified version) of type[KeyType : [Entity]]
- changing
entities
tocommittedEntities
resolves all errors
// Remove entity from parent and dictionary
entityForRemoval.removeFromParent()
for var (key, entitiesForKey) in entities {
for (i, entity) in entitiesForKey.enumerated() {
if (entity == entityForRemoval) {
entitiesForKey.remove(at: i)
}
}
}