Skip to content

Conditionals inside Group { … } crash the Swift type checker #155

@leogdion

Description

@leogdion

Repro

Minimal:

import SyntaxKit

let _ = Group {
    if true {
        Struct("A") { Variable(.let, name: "x", type: "Int") }
    }
}

Compile (or interpret via swift Repro.swift) against SyntaxKit:

error: failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
let _ = Group {
        ^

Expected

The CodeBlockBuilderResult declares both forks of buildEither and buildOptional (Sources/SyntaxKit/CodeBlocks/CodeBlockBuilderResult.swift:46-58), so the API surface advertises support for if/else inside Group { … }. The expectation is that the conditional contributes (or not) a Struct to the group like any other CodeBlock.

Actual

The Swift compiler bails on type inference with error: failed to produce diagnostic for expression — a type-checker timeout / failed solver, not a useful diagnostic. The body compiles fine when the if is removed.

Notes

  • Reproduces on Swift 6.x / macOS, both in swift script mode and swiftc compile mode.
  • The variadic buildBlock(_ components: any CodeBlock...) overload combined with buildEither overload resolution is the most likely culprit — both EmptyCodeBlock-typed branches and concrete CodeBlock branches need to unify through the existential any CodeBlock.
  • No test under Tests/SyntaxKitTests/Unit/ exercises an if inside Group { … }, which is why this hasn't been caught.

Surfaced from

Issue #154 — POC step 1 for a SyntaxKit-driven codegen CLI. See Docs/research/poc-step1-results.md §4. Not blocking that work, but blocks users who want to write conditional codegen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions