You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then, consider the following code that uses that function:
classFoo {
varbar: Int = 1
}
leta = modify(Foo()) { (i: inoutFoo) ini.bar = 2
}
The value of a.bar in the above example is 2, as expected.
However, after removing (i: inout Foo) in, which should be inferred by the compiler, the following code successfully compiles and crashes at runtime with a memory corruption error:
The value of b.bar in this case is 2, as expected.
Possibly connected issue
The above bug seems connected with the requirement to explicitly write (foo: inout Bar) in every time a closure mutates something in place, no matter if it's a struct or a class. This is not the expected behavior, though, as the compiler should automatically infer (from the closure's type) that the parameter is inout.
The text was updated successfully, but these errors were encountered:
Environment
macOS 10.12 (16A323)
Xcode 8.0 (8A218a)
Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)
Additional Detail from JIRA
md5: 04ee089f1aadca2513f2f24eb7e7ee07
duplicates:
Issue Description:
Details
Consider the following function, taking a
subject
and modifying it in place using a providedclosure
:Then, consider the following code that uses that function:
The value of
a.bar
in the above example is2
, as expected.However, after removing
(i: inout Foo) in
, which should be inferred by the compiler, the following code successfully compiles and crashes at runtime with a memory corruption error:Workarounds
The following special overload of
modify
function produces the expected result with the same test code (b
) as above:The value of
b.bar
in this case is2
, as expected.Possibly connected issue
The above bug seems connected with the requirement to explicitly write
(foo: inout Bar) in
every time aclosure
mutates something in place, no matter if it's a struct or a class. This is not the expected behavior, though, as the compiler should automatically infer (from the closure's type) that the parameter isinout
.The text was updated successfully, but these errors were encountered: