4

This will fail to compile with the error:

Immutable value 'self.constantValue' must not be passed inout

class Test {
    let constantValue: String = ""


    init() {
        Test.makeABC(&constantValue)
    }

    static func makeABC(_ string: inout String) {
        string = "ABC"
    }
}

However this will compile and actually mutate the let constant.

class Test {
    let constantValue: String = ""


    init() {
        try? Test.makeABC(&constantValue)
    }

    static func makeABC(_ string: inout String) throws {
        string = "ABC"
    }
}

Does anyone know why this works and if it is intended behavior?

I have filed a bug https://bugs.swift.org/browse/SR-8368

wshamp
  • 129
  • 4

0 Answers0