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-8074] EXC_BAD_ACCESS with curried mutating instance method. #50607
Comments
The SIL for the X.add curry thunk is wrong – there's a spurious `copy_addr` in there:
I think this is a regression from the +0 arguments work. |
Comment by Vatsal Manot (JIRA) @slavapestov is there a workaround for this? I've been using this in a generic context: @inlinable public func build<T, U, V>(_ x: T, with f: ((inout T) throws -> ((U) -> V)), _ y: U) rethrows -> T
{
var x = x
_ = try f(&x)(y)
return x
} |
So using an unbound method reference like X.add in this case is not a good idea if the method is mutating, because you get undefined behavior if the method reference is allowed to escape. In this example, you're immediately applying it twice, so we could make it work again. As a workaround, just write an explicit closure instead of referencing X.add. |
You can change build() to take a |
Comment by Vatsal Manot (JIRA) @slavapestov I've been using this to shorten: var x = self
x.mutatingFunc()
return x ... in about 78 callsites. |
Comment by Vatsal Manot (JIRA) Ah... I see. Thank you for the prompt response! |
@swift-ci create |
I don’t think we can reasonably make this work at all with inout exclusivity enforcement, so we’re going to have to break compatibility here. At one point we had code that banned partial application of mutating methods, but that must have either broke, or there’s a loophole. We should figure out why it isn’t getting diagnosed. |
Here's a patch that warns in this case (upgraded to an error in Swift 5 mode): #17642 |
Merged. You should get a warning now that this isn't really supported. |
Environment
Swift 4.2, Xcode 10 beta 1.
Additional Detail from JIRA
md5: e929ac025b57a3a6742eb1cd9eb3303c
Issue Description:
The following crashes with EXC_BAD_ACCESS. The addition of `foo` seems to be the cause.
The text was updated successfully, but these errors were encountered: