[swift-users] inout params seem to have undefined behavior

Jens Alfke jens at mooseyard.com
Mon Jun 13 15:39:59 CDT 2016


> On Jun 13, 2016, at 9:45 AM, Joe Groff via swift-users <swift-users at swift.org> wrote:
> 
> It's not undefined behavior in that we try to ensure that memory safety is still preserved when inout parameters alias, but it is *unspecified* when updates to an inout parameter will be written back to the original argument.

But it seems that memory safety was broken in that an array assigned to a ‘let’ variable was mutated. Doesn’t that violate the contract of its immutability?

Edited version of the example:
>>   let acopy = a
>>  print(acopy)  // prints "[1, 2, 3]"
>>   b = 99
>>   print(acopy)  // prints "[1, 2, 99]" (e.g. a let variable changed!)


—Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160613/debd98db/attachment.html>


More information about the swift-users mailing list