swift: Type-Check Fails to Finish in a Reasonable Time

I am currently trying to build an iOS app with a toolchain based on the 5.8 branch. The app compiled fine with Swift 5.7 but now fails due to the type-checking. I extracted following snippet to show case the problem:

import Combine
import SwiftUI

class LoginViewModel: ObservableObject, LoginDelegate {
    enum State {
        case a
        case b
        case c
        case d
    }
    
    @Published var state: State
    @Published var showAccountActivationView = false
    ... 
import SwiftUI

struct LoginView: View {
    @ObservedObject var viewModel: LoginViewModel
    
    var body: some View {
        Group {
            if viewModel.showAccountActivationView {
                <do some stuff on the viewModel>
            } else if viewModel.state == .a {
                <do some stuff on the viewModel>
            } else if viewModel.state == .b {
                <do some stuff on the viewModel>
            } else if viewModel.state == .c {
                <do some stuff on the viewModel>
            } else if viewModel.state == .d {
                <do some stuff on the viewModel>
            }
        }
    ...

If I try to compile the files containing these snippets I get following error:

<path>/LoginView.swift:6:25: error: the compiler is unable to type-check this expression in reasonable time; 
try breaking up the expression into distinct sub-expressions
    var body: some View {

Removing one of the conditions instructions seems to make it compile fine. Any ideas what could be possibly causing a regression there?

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

Thank you for the detailed information. I will look into it.

It’s up to you, I like the version with if/switch better.

No worries! Regardless I’d suggest you switch to use switch where possible that should improve your build type in general.