Open
Description
Previous ID | SR-11515 |
Radar | None |
Original Reporter | miku1958 (JIRA User) |
Type | Bug |
Attachment: Download
Additional Detail from JIRA
Votes | 1 |
Component/s | Compiler |
Labels | Bug |
Assignee | None |
Priority | Medium |
md5: 7e7f4c3a36697f342b37540042f49f0c
Issue Description:
I use @_dynamicReplacement to replace a Objc method and it work, but I can't call the original method, once I call the original method, app will get into a dead circle, keep call the alternative method until crash.
like:
extension UIResponder {
@_dynamicReplacement(for: motionEnded(_ : with:))
func motionEnded_SGR(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
motionEnded(motion, with: event)
}
}
If a replace a swift dynamic function, it can call the original dynamic function
you can try this in the example project, run in iOS device and shake
And swift compiler always crash in the first time if I add @_dynamicReplacement to the project, and if I compile success then I add @_dynamicReplacement, it will compile success
I can't provide my project, but there are crash info that Xcode output:
Stack dump:
0. Program arguments: is too long I put it in the comment
1. Contents of /var/folders/l7/mhg7cfmj0j75967x91zxjw0m0000gn/T/sources-db2c30:
---
listing swift file
---
2. While type-checking getter for numberValue (at /Users/mikun/Desktop/myProject/myProject/Classes/General/Storage/KeyValueStore/Store/StoreValue.swift:31:16)
3. While type-checking statement at [/Users/mikun/Desktop/myProject/myProject/Classes/General/Storage/KeyValueStore/Store/StoreValue.swift:31:39 - line:51:5] RangeText="{
if self.value == nil { return nil}
if let num = self.value as? NSNumber {
return num
} else {
do {
let result: Any? = try JSONSerialization.jsonObject(with: self.value), options: .allowFragments)
if let num = result as? [NSNumber] {
return num[0]
} else {
return nil
}
} catch {
print("faild to get json data")
return nil
}
}
"
4. While type-checking statement at [/Users/mikun/Desktop/myProject/myProject/Classes/General/Storage/KeyValueStore/Store/StoreValue.swift:34:9 - line:49:9] RangeText="if let num = self.value as? NSNumber {
return num
} else {
do {
let result: Any? = try JSONSerialization.jsonObject(with: self.value), options: .allowFragments)
if let num = result as? [NSNumber] {
return num[0]
} else {
return nil
}
} catch {
print("faild to get json data")
return nil
}
"
5. While type-checking statement at [/Users/mikun/Desktop/myProject/myProject/Classes/General/Storage/KeyValueStore/Store/StoreValue.swift:36:16 - line:49:9] RangeText="{
do {
let result: Any? = try JSONSerialization.jsonObject(with: self.value), options: .allowFragments)
if let num = result as? [NSNumber] {
return num[0]
} else {
return nil
}
} catch {
print("faild to get json data")
return nil
}
"
6. While type-checking statement at [/Users/mikun/Desktop/myProject/myProject/Classes/General/Storage/KeyValueStore/Store/StoreValue.swift:37:13 - line:47:13] RangeText="do {
let result: Any? = try JSONSerialization.jsonObject(with: self.value), options: .allowFragments)
if let num = result as? [NSNumber] {
return num[0]
} else {
return nil
}
} catch {
print("faild to get json data")
return nil
"
7. While type-checking statement at [/Users/mikun/Desktop/myProject/myProject/Classes/General/Storage/KeyValueStore/Store/StoreValue.swift:37:16 - line:44:13] RangeText="{
let result: Any? = try JSONSerialization.jsonObject(with: self.value), options: .allowFragments)
if let num = result as? [NSNumber] {
return num[0]
} else {
return nil
}
"
8. While type-checking declaration 0x7fb22b13f078 (at /Users/mikun/Desktop/myProject/myProject/Classes/General/Storage/KeyValueStore/Store/StoreValue.swift:38:17)
9. While type-checking expression at [/Users/mikun/Desktop/myProject/myProject/Classes/General/Storage/KeyValueStore/Store/StoreValue.swift:38:36 - line:38:156] RangeText="try JSONSerialization.jsonObject(with: self.value), options: .allowFragments"
10. While evaluating request IsObjCRequest(myProject.(file).UIResponder extension.motionEnded_shake(_:with🙂@/Users/mikun/Desktop/myProject/myProject/Classes/System/AppDelegate.swift:18:7)
0 swift 0x0000000113426eb3 PrintStackTraceSignalHandler(void\*) + 51
1 swift 0x0000000113426686 SignalHandler(int) + 358
2 libsystem_platform.dylib 0x00007fff70292b5d \_sigtramp + 29
3 libsystem_platform.dylib 0x0000000000000040 \_sigtramp + 2413221120
4 swift 0x000000010fbe4788 shouldMarkAsObjC(swift::ValueDecl const\*, bool) + 1240
5 swift 0x000000010fc54c6d swift::SimpleRequest\<swift::IsObjCRequest, (swift::CacheKind)2, bool, swift::ValueDecl\*\>::evaluateRequest(swift::IsObjCRequest const&, swift::Evaluator&) + 109
6 swift 0x000000010ff59deb swift::IsObjCRequest::OutputType swift::evaluateOrDefault\<swift::IsObjCRequest\>(swift::Evaluator&, swift::IsObjCRequest, swift::IsObjCRequest::OutputType) + 1179
7 swift 0x000000010ffe5097 swift::SourceFile::LookupCache::addToMemberCache(swift::IteratorRange\<swift::DeclIterator\>) + 119
8 swift 0x000000010ffe3119 swift::SourceFile::lookupClassMember(llvm::ArrayRef\<std::\_\_1::pair\<swift::Identifier, swift::SourceLoc\> \>, swift::DeclName, llvm::SmallVectorImpl\<swift::ValueDecl\*\>&) const + 313
9 swift 0x0000000110000278 void llvm::function_ref\<void (std::**1::pair\<llvm::ArrayRef\<std::1::pair\<swift::Identifier, swift::SourceLoc\> \>, swift::ModuleDecl\*\>)\>::callback_fn\<swift::DeclContext::lookupAnyObject(swift::DeclName, swift::NLOptions, llvm::SmallVectorImpl\<swift::ValueDecl\*\>&) const::$*8 const\>(long, std::1::pair\<llvm::ArrayRef\<std::*\_1::pair\<swift::Identifier, swift::SourceLoc\> \>, swift::ModuleDecl\*\>) + 104
10 swift 0x000000010f3c6994 bool llvm::function_ref\<bool (std::1::pair\<llvm::ArrayRef\<std::1::pair\<swift::Identifier, swift::SourceLoc\> \>, swift::ModuleDecl\*\>)\>::callback_fn\<swift::FileUnit::forAllVisibleModules(llvm::function_ref\<void (std::1::pair\<llvm::ArrayRef\<std::1::pair\<swift::Identifier, swift::SourceLoc\> \>, swift::ModuleDecl\*\>)\>)::'lambda'(std::1::pair\<llvm::ArrayRef\<std::1::pair\<swift::Identifier, swift::SourceLoc\> \>, swift::ModuleDecl\*\>)\>(long, std::1::pair\<llvm::ArrayRef\<std::*\_1::pair\<swift::Identifier, swift::SourceLoc\> \>, swift::ModuleDecl\*\>) + 52
11 swift 0x000000010ffed1ec swift::ModuleDecl::forAllVisibleModules(llvm::ArrayRef\<std::1::pair\<swift::Identifier, swift::SourceLoc\> \>, llvm::function_ref\<bool (std::1::pair\<llvm::ArrayRef\<std::*\_1::pair\<swift::Identifier, swift::SourceLoc\> \>, swift::ModuleDecl\*\>)\>) + 476
12 swift 0x000000010ffed354 swift::FileUnit::forAllVisibleModules(llvm::function_ref\<bool (std::\_*1::pair\<llvm::ArrayRef\<std::*\_1::pair\<swift::Identifier, swift::SourceLoc\> \>, swift::ModuleDecl\*\>)\>) + 52
13 swift 0x000000010ffff71d swift::DeclContext::lookupQualified(swift::Type, swift::DeclName, swift::NLOptions, swift::LazyResolver\*, llvm::SmallVectorImpl\<swift::ValueDecl\*\>&) const + 493
14 swift 0x000000010fc06313 swift::TypeChecker::lookupMember(swift::DeclContext\*, swift::Type, swift::DeclName, swift::OptionSet\<swift::NameLookupFlags, unsigned int\>) + 371
15 swift 0x000000010fb14b4e swift::constraints::ConstraintSystem::lookupMember(swift::Type, swift::DeclName) + 254
16 swift 0x000000010fa9e1dc swift::constraints::ConstraintSystem::performMemberLookup(swift::constraints::ConstraintKind, swift::DeclName, swift::Type, swift::FunctionRefKind, swift::constraints::ConstraintLocator\*, bool) + 2908
17 swift 0x000000010faa9ce8 swift::constraints::ConstraintSystem::simplifyMemberConstraint(swift::constraints::ConstraintKind, swift::Type, swift::DeclName, swift::Type, swift::DeclContext\*, swift::FunctionRefKind, llvm::ArrayRef\<swift::constraints::OverloadChoice\>, swift::OptionSet\<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int\>, swift::constraints::ConstraintLocatorBuilder) + 504
18 swift 0x000000010fa76c22 swift::constraints::ConstraintSystem::addValueMemberConstraint(swift::Type, swift::DeclName, swift::Type, swift::DeclContext\*, swift::FunctionRefKind, llvm::ArrayRef\<swift::constraints::OverloadChoice\>, swift::constraints::ConstraintLocatorBuilder) + 98
19 swift 0x000000010fa77111 (anonymous namespace)::ConstraintGenerator::addMemberRefConstraints(swift::Expr\*, swift::Expr\*, swift::DeclName, swift::FunctionRefKind, llvm::ArrayRef\<swift::ValueDecl\*\>) + 737
20 swift 0x000000010fa706b8 swift::ASTVisitor\<(anonymous namespace)::ConstraintGenerator, swift::Type, void, void, void, void, void\>::visit(swift::Expr\*) + 7960
21 swift 0x000000010fa6d78d (anonymous namespace)::ConstraintWalker::walkToExprPost(swift::Expr\*) + 141
22 swift 0x000000010ff3312b (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr\*) + 123
23 swift 0x000000010ff2f292 swift::ASTVisitor\<(anonymous namespace)::Traversal, swift::Expr\*, swift::Stmt\*, bool, swift::Pattern\*, bool, void\>::visit(swift::Expr\*) + 130
24 swift 0x000000010ff305b2 swift::ASTVisitor\<(anonymous namespace)::Traversal, swift::Expr\*, swift::Stmt\*, bool, swift::Pattern\*, bool, void\>::visit(swift::Expr\*) + 5026
25 swift 0x000000010ff33183 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr\*) + 211
26 swift 0x000000010ff2f315 swift::ASTVisitor\<(anonymous namespace)::Traversal, swift::Expr\*, swift::Stmt\*, bool, swift::Pattern\*, bool, void\>::visit(swift::Expr\*) + 261
27 swift 0x000000010fa67d01 swift::constraints::ConstraintSystem::generateConstraints(swift::Expr\*, swift::DeclContext\*) + 849
28 swift 0x000000010fabb1e2 swift::constraints::ConstraintSystem::solve(swift::Expr\*&, swift::Type, swift::ExprTypeCheckListener\*, llvm::SmallVectorImpl\<swift::constraints::Solution\>&, swift::FreeTypeVariableBinding) + 8338
29 swift 0x000000010fbb43e2 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr\*&, swift::DeclContext\*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet\<swift::TypeCheckExprFlags, unsigned int\>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem\*) + 1042
30 swift 0x000000010fbb80c2 swift::TypeChecker::typeCheckBinding(swift::Pattern\*&, swift::Expr\*&, swift::DeclContext\*) + 898
31 swift 0x000000010fbb8e21 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl\*, unsigned int) + 225
32 swift 0x000000010fbc559a (anonymous namespace)::DeclChecker::visit(swift::Decl\*) + 7786
33 swift 0x000000010fc6689e swift::ASTVisitor\<(anonymous namespace)::StmtChecker, void, swift::Stmt\*, void, void, void, void\>::visit(swift::Stmt\*) + 23774
34 swift 0x000000010fc66e21 bool (anonymous namespace)::StmtChecker::typeCheckStmt\<swift::Stmt\>(swift::Stmt\*&) + 129
35 swift 0x000000010fc616f1 swift::ASTVisitor\<(anonymous namespace)::StmtChecker, void, swift::Stmt\*, void, void, void, void\>::visit(swift::Stmt\*) + 2865
36 swift 0x000000010fc66e21 bool (anonymous namespace)::StmtChecker::typeCheckStmt\<swift::Stmt\>(swift::Stmt\*&) + 129
37 swift 0x000000010fc668b3 swift::ASTVisitor\<(anonymous namespace)::StmtChecker, void, swift::Stmt\*, void, void, void, void\>::visit(swift::Stmt\*) + 23795
38 swift 0x000000010fc66e21 bool (anonymous namespace)::StmtChecker::typeCheckStmt\<swift::Stmt\>(swift::Stmt\*&) + 129
39 swift 0x000000010fc60ed4 swift::ASTVisitor\<(anonymous namespace)::StmtChecker, void, swift::Stmt\*, void, void, void, void\>::visit(swift::Stmt\*) + 788
40 swift 0x000000010fc66e21 bool (anonymous namespace)::StmtChecker::typeCheckStmt\<swift::Stmt\>(swift::Stmt\*&) + 129
41 swift 0x000000010fc668b3 swift::ASTVisitor\<(anonymous namespace)::StmtChecker, void, swift::Stmt\*, void, void, void, void\>::visit(swift::Stmt\*) + 23795
42 swift 0x000000010fc60b61 bool (anonymous namespace)::StmtChecker::typeCheckStmt\<swift::BraceStmt\>(swift::BraceStmt\*&) + 129
43 swift 0x000000010fc60660 swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl\*, swift::SourceLoc) + 5456
44 swift 0x000000010fc687c1 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl\*) + 561
45 swift 0x000000010fc852c2 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet\<swift::TypeCheckingFlags, unsigned int\>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 2082
46 swift 0x000000010f3813ab swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t)::$\_0::operator()(swift::SourceFile&) const + 91
47 swift 0x000000010f38010b swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 5371
48 swift 0x000000010f07598f performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef\<char const\*\>, int&, swift::FrontendObserver\*, swift::UnifiedStatsReporter\*) + 815
49 swift 0x000000010f071e54 swift::performFrontend(llvm::ArrayRef\<char const\*\>, char const\*, void\*, swift::FrontendObserver\*) + 6820
50 swift 0x000000010efff3c3 main + 1219
51 libdyld.dylib 0x00007fff700a73d5 start + 1
52 libdyld.dylib 0x00000000000001bb start + 2415234535
error: Segmentation fault: 11 (in target 'myProject' from project 'myProject')