Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-8209] Operation subclasses behaviour depends on compilation order #50741

Closed
swift-ci opened this issue Jul 9, 2018 · 5 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.1

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 9, 2018

Previous ID SR-8209
Radar None
Original Reporter dekr (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 9.4.1 + Swift 4.0

Works on 9.2 and 10

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.1Regression, Miscompile
Assignee None
Priority Medium

md5: 2a99a6d99d406cd455fb30474ad8d5b2

Issue Description:

We have two subclasses of `Operation` (Operation -> AsyncOperation ->

AsyncValueBlockOperation) that override `isAsynchronous` property:

open class AsyncOperation: Operation {
  override open var isAsynchronous: Bool { return true }
}

public final class AsyncValueBlockOperation: AsyncOperation {
  public override var isAsynchronous: Bool { return false }
}

Execution code:

let _ = AsyncValueBlockOperation().isAsynchronous

And their behaviour depends on compilation order.

If we place classes in that order and try to execute code the result will be a crash.

Crash:

2018-07-09 13:02:13.382072+0300 InheritanceProblem[25255:1883449] -[InheritanceProblem.AsyncValueBlockOperation asynchronous]: unrecognized selector sent to instance 0x102a06ff0

2018-07-09 13:02:13.385179+0300 InheritanceProblem[25255:1883449] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[InheritanceProblem.AsyncValueBlockOperation asynchronous]: unrecognized selector sent to instance 0x102a06ff0'

*** First throw call stack:
(
0   CoreFoundation                      0x00007fff5721132b __exceptionPreprocess + 171
1   libobjc.A.dylib                     0x00007fff7e367c76 objc_exception_throw + 48
2   CoreFoundation                      0x00007fff572a9e04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3   CoreFoundation                      0x00007fff57187870 ___forwarding___ + 1456
4   CoreFoundation                      0x00007fff57187238 _CF_forwarding_prep_0 + 120
5   InheritanceProblem                  0x0000000100001c24 main + 52
6   libdyld.dylib                       0x00007fff7ef81015 start + 1
7   ???                                 0x0000000000000001 0x0 + 1
)

libc++abi.dylib: terminating with uncaught exception of type NSException

Program ended with exit code: 9

If we change order of classes definitions the code will work properly.

@belkadan
Copy link
Contributor

belkadan commented Jul 9, 2018

Yikes! Which version of Xcode are you using?

@belkadan
Copy link
Contributor

belkadan commented Jul 9, 2018

Seems to be working for me using Xcode 10b1.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jul 9, 2018

Comment by Denis (JIRA)

Of course. The problems showed up when we started using Xcode 9.4.1

@belkadan
Copy link
Contributor

belkadan commented Jul 9, 2018

Cool, then I'm going to say this is fixed! It sounds a lot like SR-6944, though it's not exactly the same.

@belkadan
Copy link
Contributor

belkadan commented Jul 9, 2018

Adding a test case to catch regressions in #17838

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.1
Projects
None yet
Development

No branches or pull requests

3 participants