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-11891] Associated Type in protocol results in bad argument pointer in generic closure #54308

Closed
swift-ci opened this issue Dec 3, 2019 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Dec 3, 2019

Previous ID SR-11891
Radar rdar://problem/57711775
Original Reporter lickel (JIRA User)
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

Swift 5.x on Apple platforms

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

md5: 70765ca8f079ddb30954d57fcaa981bb

Issue Description:

I rely upon a closure for type erasure at a different layer.

When I set a breakpoint and inspect the variable at each level, it is valid at the top of the call stack, as it goes down into closures the memory gets disassociated and I can no longer inspect the value.

In Swift 5.x, the closure and method dispatch do not crash, but the evaluation is incorrect.

If I use a typealias, then everything works as expected.

I have a cleanly compiling project with clean unit tests.

When I apply the attached patch, I would expect the same to be true.

What happens today is everything compiles, but some unit tests fail.

https://github.com/crewos/fetchrequests

--

This has not worked in most versions of Swift.

In at least one version it had worked – I think the swift 4 betas.

In prior versions of Swift the evaluation would crash.

In Swift 5.x it does not crash, but the pointer addresses are invalid.

In the past, the RawData type was a [String: Any], which had the same problems.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Dec 3, 2019

Comment by Adam Lickel (JIRA)

If I set a breakpoint in `FetchedResultsControllerTestCase.testExpectNoInsertFromBroadcastNotification()`, on line 887, the json parameter is believed to be of case `number`.
Printing the description, it's clear that something was misassigned:

Printing description of json:
▿ JSON
{{ - number : TtGCs18_DictionaryStorageSSP_$}}

If I walk up the call stack to FetchedResultsController.observedObjectUpdate(_🙂 on line 987, it's of case `dictionary`.

The intermediate thunks caused this memory corruption.

@beccadax
Copy link
Contributor

beccadax commented Dec 6, 2019

@swift-ci create

@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
Projects
None yet
Development

No branches or pull requests

2 participants