Skip to content

Unresolved name causes "Failed to produce diagnostic for expression..." error #60029

Closed
@samrshi

Description

@samrshi

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

  1. Paste the following code into Xcode or an Xcode Playground (possibly only using Xcode 14 beta 3/the version of Swift it runs).
  2. Attempt to build (or run in an Xcode Playground).
  3. 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 - in playground

Simplified Snippet in .xcodeproj
simplified - 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!

original-ish in xcodeproj

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 type Entity
  • there is a class property called committedEntities (the correctName in the simplified version) of type [KeyType : [Entity]]
  • changing entities to committedEntities 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)
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationfailed to produce diagnosticBug → internal error: Failed to produce diagnostic for expressiontype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions