After latest update: The compiler is unable to type-check this expression in reasonable time

Hello, since the latest update of Xcode (Version 15.3 (15E204a)) and Simulator I have the following error message when trying to run my App: "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions." My App was running with Simulator and on my iPad without any problems with exactly the same code! A similar version is already running on TestFlight with nearly the same code. What can I do to make my App run again?

Answered by szymczyk in 783339022

You are doing a lot in the .onChange block. To fix the compiler error, I recommend creating a function to calculate the value of P_Sprint and call the function in the .onChange block. Breaking up the calculations into smaller chunks will also help you fix the compiler error and make the code easier to understand.

If the code was working in Xcode 15.2 and you want to publish your app without making the code changes, then install Xcode 15.2. Build, archive, and submit your project in Xcode 15.2. Apple doesn't require Xcode 15.3 for App Store submissions.

Use the site Xcode Releases to find Apple's download links for all Xcode versions.

https://xcodereleases.com

No one can give you an answer until you show the code that is causing the compiler error.

As szymczyk says, it’s hard to offer a good answer without more info about your code. However, there are some things common to all such issues.

This is a compile-time error, not a runtime error, so the fact that your previous code is still running in TestFlight isn’t a surprise.

At some fundamental level all instances of this problem could be considered a compiler bug (or maybe an opportunity for an improvement in the compiler :-). That’s especially true here, where things have regressed from a previous version of the compiler. If you’re able to distill this down into a small test project that compiles with Xcode 15.2 but fails in this way with Xcode 15.3, it’d be great if you could file a bug with that project.

As to what you can do about it, the advice in the error message is sound. This problem is triggered by code that relies on extensive type inferencing. The compiler has to search a large space of possible type combinations that might allow the code to work. You typically see this when working with:

  • Literal numbers — For example, a 1 could be interpreted as Int, UInt, UInt8, Dobule, Float, and so on.

  • Arithmetic operators — For example, a + might be adding together two Int values, two UInt values, and so on.

You can often prevent the problem by either splitting up the expression or applying a type constraint. For example, you might rewrite:

let x = 1 * 2 + 3

as:

let p = 1 * 2
let x = p + 3

or:

let x = 1 as Int * 2 + 3

or:

let x: Int = 1 * 2 + 3

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Here is some of the code: var body: some View { HStack { Text("(person.name ?? "Error") (person.vorname ?? "Error"), (person.klasse ?? "Error")") .fontWeight(.bold) .frame(width: 160, alignment: .leading)

        Spacer(minLength: 20)
        VStack {
        Picker("Sprint", selection: $selectedSprint) {
            ForEach(sprints, id: \.self) { sprint in
                Text(sprint)
            }
        }
        .pickerStyle(SegmentedPickerStyle())
        .background(Color(UIColor(red: 135/255, green: 206/255, blue: 255/255, alpha: 1)))
        .overlay(
            RoundedRectangle(cornerRadius: 5)
                .stroke(Color.white, lineWidth: 3))
        .onAppear {
            selectedSprint = person.dsprint ?? ""
        }
        
        .onChange(of: selectedSprint) { value in
            person.dsprint = value
            
            if let ergSprint = numberFormatter.number(from: ergebnisSprint)?.doubleValue {
                
                if person.gender == "w" && selectedSprint == "50" {
                    
                    P_Sprint = Int16(floor(( (50 / ( ergSprint + 0.24 ) - 3.648 ) ) / 0.0066))
                }
                if person.gender == "w" && selectedSprint == "75" {
                    
                    P_Sprint = Int16(floor(( (75 / ( ergSprint + 0.24 ) - 3.998 ) ) / 0.0066))
                }
                if person.gender == "w" && selectedSprint == "100" {
                    
                    P_Sprint = Int16(floor(( (100 / ( ergSprint + 0.24 ) - 4.0062 ) ) / 0.00656))
                }
                if person.gender == "w" && selectedSprint == "50 el" {
                    
                    P_Sprint = Int16(floor(( (50 / ergSprint - 3.648 ) ) / 0.0066))
                }
                if person.gender == "w" && selectedSprint == "75 el" {
                    
                    P_Sprint = Int16(floor(( (75 / ergSprint - 3.998 ) ) / 0.0066))
                }
                if person.gender == "w" && selectedSprint == "100 el" {
                    
                    P_Sprint = Int16(floor(( (100 / ergSprint - 4.0062 ) ) / 0.00656))
                }
                if person.gender == "m" && selectedSprint == "50" {
                    
                    P_Sprint = Int16(floor(( (50 / ( ergSprint + 0.24 ) - 3.79 ) ) / 0.0069))
                }
                if person.gender == "m" && selectedSprint == "75" {
                    
                    P_Sprint = Int16(floor(( (75 / ( ergSprint + 0.24 ) - 4.1) ) / 0.00664))
                }
                if person.gender == "m" && selectedSprint == "100" {
                    
                    P_Sprint = Int16(floor(( (100 / ( ergSprint + 0.24 ) - 4.341 ) ) / 0.00676))
                }
                if person.gender == "m" && selectedSprint == "50 el" {
                    
                    P_Sprint = Int16(floor(( (50 / ergSprint - 3.79 ) ) / 0.0069))
                }
                if person.gender == "m" && selectedSprint == "75 el" {
                    
                    P_Sprint = Int16(floor(( (75 / ergSprint - 4.1 ) ) / 0.00664))
                }
                if person.gender == "m" && selectedSprint == "100 el" {
                    
                    P_Sprint = Int16(floor(( (100 / ergSprint - 4.341 ) ) / 0.00676))
                }
             
                
            }
Accepted Answer

You are doing a lot in the .onChange block. To fix the compiler error, I recommend creating a function to calculate the value of P_Sprint and call the function in the .onChange block. Breaking up the calculations into smaller chunks will also help you fix the compiler error and make the code easier to understand.

If the code was working in Xcode 15.2 and you want to publish your app without making the code changes, then install Xcode 15.2. Build, archive, and submit your project in Xcode 15.2. Apple doesn't require Xcode 15.3 for App Store submissions.

Use the site Xcode Releases to find Apple's download links for all Xcode versions.

https://xcodereleases.com

https://developer.apple.com/forums/thread/748729

szymczyk wrote:

Use the site Xcode Releases to find Apple's download links for all Xcode versions.

Please don’t recommend third-party websites for downloading Xcode. There’s historical precedent for this going horribly wrong. You can download older versions of Xcode from the Downloads area on the developer web site. Click More (at the top right) get to the archive.


Vestus wrote:

Here is some of the code

I agree with szymczyk that factoring this out into a function is likely to help.

Here’s what I’d do in this situation:

  • Change your .gender property to an enum. That simplifies your code, making it possible for the compiler to check your work.

  • Likewise for the selectedSprint value.

  • All your sprint calculations look the same. You take ergSprint, add a number to it, divide that into the sprint length, optionally add (well subtract) another number, and then finally divide by a final number. You could represent this as a single statement:

P_Sprint = ( (sprintLength / ( ergSprint + f1) - f2 ) ) / f3

Then use a bit switch statement to set up these factors:

let f1: Double
let f2: Double
let f3: Double
switch (person.general, sprintLength) {
case (.male, sprintLength):
  f1 = 0.25
  f2 = -3.79
  f3 = 0.0069
… other cases …
}

That’s simplify your code radically, which should make things easier for both you and the compiler.

Could it be helpful for me to ask for some "Code level support" in this case?

Probably not. DTS’s focus is on helping folks having problems with the APIs in Apple various platform SDKs. This issue is more about your code than Apple’s APIs.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

After latest update: The compiler is unable to type-check this expression in reasonable time
 
 
Q