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
structAccumulator {
varvalue = 0mutatingfuncdoIt(_n: Int) {
value += n
}
mutatingfunccallAsFunction(_n: Int) {
doIt(n)
}
}
letresult1 = [1, 2, 3, 4].reduce(into: Accumulator()) {
$0.doIt($1) // 1) call mutating is fine here
}
.value// this should work, but do notletresult2 = [1, 2, 3, 4].reduce(into: Accumulator()) {
// 2)// in Xcode 12.5b2 playground:// error: cannot use mutating member on immutable value: '$0' is immutable// in iPad Playground:// Type of expression is ambiguous without more context$0($1)
}
.valueletresult3 = [1, 2, 3, 4].reduce(into: Accumulator()) { (a: inoutAccumulator, n: Int) ina(n) // 3) this is fine
}
.value
Still do not compile in Xcode 13.0 beta 2. The odd thing is even with named closure parameter that was working in Xcode 13.0 beta 1 is now broken same error as the shorthand parameters.
But then Xcode 13.0 beta 2 came out and the named version now back to working.
And Xcode Version 13.0 beta 3 (13A5192i) breaks again
structAccumulator {
varvalue = 0mutatingfuncdoIt(_n: Int)
{ value += n }
mutatingfunccallAsFunction(_n: Int)
{ doIt(n) }
}
letresult0 = [1, 2, 3, 4].reduce(into: Accumulator()) {
$0($1) // still compile error: Cannot use mutating member on immutable value: '$0' is immutable
}
.value// what? It works now in Xcode Version 13.0 beta (13A5155e) (beta 2)letresult1 = [1, 2, 3, 4].reduce(into: Accumulator()) { (a: inoutAccumulator, n: Int) ina(n) // compile error in Xcode 13.0 beta 1// works fine now in beta 2
}
.valueletresult2 = [1, 2, 3, 4].reduce(into: Accumulator()) { (a: inoutAccumulator, n: Int) ina.doIt(n)
}
.value
Attachment: Download
Additional Detail from JIRA
md5: 5087e27f26c82f7087f2bb64b451af5f
Issue Description:
Xcode Version 12.5 beta 2 (12E5234g)
see: https://forums.swift.org/t/reduce-into-why-cannot-use-callasfunction-syntax-cannot-use-mutating-member-on-immutable-value-0-is-immutable/44861/5
The text was updated successfully, but these errors were encountered: