Weird runtime crash #1564
-
I have the following state, as part of a child: public struct State: Equatable {
public enum Status: Equatable {
case initial
case loading
case error(VitalError)
}
public var status: Status = .initial
public var alert: AlertState<Action>?
public var code: String = ""
init(
status: Status = .initial,
alert: AlertState<Action>? = nil,
code: String = ""
) {
self.status = status
self.alert = alert
self.code = code
}
} And the child being used in the parent: public var body: some ReducerProtocol<State, Action> {
Reduce { state, action in
switch action {
case let .handleResult(credentials):
if let credentials = credentials {
state = .authenticated(.init(credentials: credentials))
return Effect(value: .authenticated(.setup))
} else {
state = .noCode(.init())
return .none
}
case .checkStatus:
let value = appDependencies.credentials()
return Effect(value: .handleResult(value))
case .noCode, .authenticated:
return .none
}
}
.ifCaseLet(/State.noCode, action: /Action.noCode) {
NoCodeReducer()
}
.ifCaseLet(/State.authenticated, action: /Action.authenticated) {
AuthenticatedReducer()
}
} If I run the above code, it crashes: However, if I put the public var status: Status = .initial
public var code: String = ""
public var alert: AlertState<Action>? I get this crash instead: If I remove the I am using What's happening here? :) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
@RuiAAPeres Hard to pinpoint the issue without more context, but a few things stand out:
There are some known bugs in case path reflection. While they are generally edge cases involving existentials and enums with one case, you might be hitting one here. We'd love to track them down (or better, we'd love for Apple to support native case paths), so any more info about the types involved here would be helpful! |
Beta Was this translation helpful? Give feedback.
-
I get this a lot too. Don't know if it's just with TCA projects, but about once a week or so I start getting unexplained crashes like the above, and a clean build or clean build + restart Xcode solves it. Must be an Xcode / Swift compiler bug related to incremental builds. |
Beta Was this translation helpful? Give feedback.
-
A few months back we found the following incremental compilation crash: swiftlang/swift#60706. It's reproducible in plain Swift code without TCA. The sample project shows the exact steps to produce the bug too. |
Beta Was this translation helpful? Give feedback.
@RuiAAPeres Hard to pinpoint the issue without more context, but a few things stand out:
State.noCode
andState.authenticated
)?CasePath.init(embed:extract:)
, does everything work just fine?There are some known bugs in case path reflection. While they are generally edge cases involving existentials and enums with one case, you might be hitting one here. We'd love to track them down (or b…