The following code results in a segmentation fault and crashes the copmpiler:
struct Action {
var intVar: Int
var strVar: String
}
protocol TestDelegate: AnyObject {
associatedtype ActionType
var actions: [ActionType] { get set }
}
class TestDelegateImpl: TestDelegate {
typealias ActionType = Action
var actions: [Action] = []
}
class TestViewController {
var testDelegate: (any TestDelegate)?
func testFunc() {
testDelegate?.actions.removeAll()
}
}
let tVC = TestViewController()
tVC.testDelegate = TestDelegateImpl()
tVC.testFunc()
The stack dump:
...
1. Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
2. Compiling with the current language version
3. While evaluating request TypeCheckSourceFileRequest(source_file "Contents.swift")
4. While evaluating request TypeCheckFunctionBodyRequest(Contents.(file).TestViewController.testFunc()@Contents.swift:18:10)
5. While type-checking statement at [Contents.swift:18:21 - line:20:5] RangeText="{
testDelegate?.actions.removeAll()
"
6. While type-checking expression at [Contents.swift:19:9 - line:19:41] RangeText="testDelegate?.actions.removeAll("
7. While type-checking-target starting at Contents.swift:19:31
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 swift-frontend 0x00000001078135b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x00000001078125b4 llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000107813c34 SignalHandler(int) + 344
3 libsystem_platform.dylib 0x00000001a29542a4 _sigtramp + 56
4 swift-frontend 0x0000000103939b38 (anonymous namespace)::ExprRewriter::coerceToType(swift::Expr*, swift::Type, swift::constraints::ConstraintLocatorBuilder, llvm::Optional<swift::Pattern*>) + 16868
5 swift-frontend 0x00000001039388c8 (anonymous namespace)::ExprRewriter::coerceToType(swift::Expr*, swift::Type, swift::constraints::ConstraintLocatorBuilder, llvm::Optional<swift::Pattern*>) + 12148
6 swift-frontend 0x000000010395c5e8 (anonymous namespace)::ExprRewriter::closeExistential(swift::Expr*&, swift::constraints::ConstraintLocatorBuilder, bool) + 340
7 swift-frontend 0x00000001039547c0 (anonymous namespace)::ExprRewriter::buildMemberRef(swift::Expr*, swift::SourceLoc, swift::constraints::SelectedOverload, swift::DeclNameLoc, swift::constraints::ConstraintLocatorBuilder, swift::constraints::ConstraintLocatorBuilder, bool, swift::AccessSemantics) + 11204
8 swift-frontend 0x0000000103941f50 swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) + 8156
9 swift-frontend 0x000000010393cd58 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 24
10 swift-frontend 0x0000000103f944e8 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 268
11 swift-frontend 0x0000000103f94538 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 348
12 swift-frontend 0x0000000103f9445c swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 128
13 swift-frontend 0x0000000103932a78 (anonymous namespace)::ExprWalker::rewriteTarget(swift::constraints::SolutionApplicationTarget) + 376
14 swift-frontend 0x00000001039325ec swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SolutionApplicationTarget) + 5852
15 swift-frontend 0x0000000103b9a104 swift::TypeChecker::typeCheckTarget(swift::constraints::SolutionApplicationTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 688
16 swift-frontend 0x0000000103b99de4 swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 400
17 swift-frontend 0x0000000103c74564 (anonymous namespace)::StmtChecker::typeCheckASTNode(swift::ASTNode&) + 300
18 swift-frontend 0x0000000103c77a64 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 328
19 swift-frontend 0x0000000103c76540 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 300
20 swift-frontend 0x0000000103c7538c swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 1276
21 swift-frontend 0x000000010406ee64 llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest>(swift::TypeCheckFunctionBodyRequest const&) + 588
22 swift-frontend 0x0000000104001e64 swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType) + 116
23 swift-frontend 0x0000000103cb1db0 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 792
24 swift-frontend 0x0000000103cb4960 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 576
25 swift-frontend 0x0000000103cb1a44 swift::performTypeChecking(swift::SourceFile&) + 120
26 swift-frontend 0x0000000102ed2b8c bool llvm::function_ref<bool (swift::SourceFile&)>::callback_fn<swift::CompilerInstance::performSema()::$_6>(long, swift::SourceFile&) + 16
27 swift-frontend 0x0000000102ecd300 swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<bool (swift::SourceFile&)>) + 288
28 swift-frontend 0x0000000102ecd1a4 swift::CompilerInstance::performSema() + 148
29 swift-frontend 0x0000000102e602ac swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4364
30 swift-frontend 0x0000000102e013c0 swift::mainEntry(int, char const**) + 3940
31 dyld 0x00000001a25fbe50 start + 2544
zsh: segmentation fault swift Contents.swift
Anyone experienced this, or do I overlook somethinig? I would expect this should work, but it seems as it has problems with type checking testDelegate?.actions.removeAll().
Post
Replies
Boosts
Views
Activity
If I simply have a Button where I have a state variable bind to its .disabled modifier, then it works nice, as expected:
struct TestView: View {
@State private var saveEnabled: Bool = true
var body: some View {
Text("Tap me!")
.onTapGesture {
saveEnabled = !saveEnabled
}
Button("Save") {}
.disabled(!saveEnabled)
}
}
With this code snippet, when the user taps the text, the button is either enabled with blue tint or disabled with greyed out tint.
But when I try to do the same within a presented alert, it does not work. My use case is that I present a text field which is prepopulated with a non empty string and then I let the user to change that, but if that's empty, I don't want to let the user to save it, so I want to disable the Button. This concept works fine in UIKit with UIAlertController and UITextField - here I'm not sure why doesn't it work.
Code snippet:
struct TestView: View {
@State private var saveEnabled: Bool = true
var body: some View {
Text("Tap me!")
.onTapGesture {
presentAlert = true
}
.alert("Change name", isPresented: $presentAlert, actions: {
TextField("", text: $name)
.onChange(of: name) { newValue in
saveEnabled = !newValue.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}
Button("Save") {}
.disabled(!saveEnabled)
}
)
}
}
Should I file a ticket in Feedback Assistant or is there something I'm overlooking? Thanks.
I have a framework (MyFramework) in which I want to use an existing dynamic framework via SPM (called now MyDynamicFramework).
I included it as a package dependency and all seems to be good:
Then, I created a test application in which I simply include my framework with Enbed & Sign.
When I run this test application, it all works fine in simulator, but in real device I get the following signing-related issue:
dyld[24248]: Library not loaded: @rpath/MyDynamicFramework.framework/MyDynamicFramework
Referenced from: <ED356026-4AD8-3AD4-9CD7-BE977EE551E4> /private/var/containers/Bundle/Application/432B2A6D-55A7-4C9D-8EA2-622B81E215EA/MyFrameworkTestApp.app/Frameworks/MyFramework.framework/MyFramework
Reason: tried: '/private/var/containers/Bundle/Application/432B2A6D-55A7-4C9D-8EA2-622B81E215EA/MyFrameworkTestApp.app/Frameworks/MyDynamicFramework.framework/MyDynamicFramework' (no such file),
'/private/var/containers/Bundle/Application/432B2A6D-55A7-4C9D-8EA2-622B81E215EA/MyFrameworkTestApp.app/Frameworks/MyFramework.framework/Frameworks/MyDynamicFramework.framework/MyDynamicFramework' (code signature in <2BD920A5-1906-31B6-99B9-18DE47F02514>
'/private/var/containers/Bundle/Application/432B2A6D-55A7-4C9D-8EA2-622B81E215EA/MyFrameworkTestApp.app/Frameworks/MyFramework.framework/Frameworks/MyDynamicFramework.framework/MyDynamicFramework' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.),
'/Users/XXXXXXX/Library/Developer/Xcode/DerivedData/MyFramework-gedzmltwlpgatndvsrwkinsfgwhr/Build/Products/Debug-iphoneos/PackageFrameworks/MyDynamicFramework.framework/MyDynamicFramework' (no such file),
...
Am I missing some settings? I thought that Embed & Sign should have solved the issue but it didn't. Thanks.
It seems that it works if I embed the MyDynamicFramework in my test application as well, even thought that's already embedded into the framework (MyFramework) that I'm using. I don't see why should I do that, isn't that including the same dynamic framework twice?