Files
swift-mirror/test/SILOptimizer/definite_init_existential_let.swift
Doug Gregor 39f4e38027 Diagnose inout uses of 'lets' in constructors in the type checker.
Stored `let` properties of a struct, class, or actor permit
'inout' modification within the constructor body after they have been
initialized. Tentatively remove this rule, only allowing such `let`
properties to be initialized (assigned to) and not treated as `inout`.

Fixes rdar://127258363.
2024-05-14 15:59:50 -07:00

28 lines
525 B
Swift

// RUN: %target-swift-frontend -emit-sil -verify %s
// rdar://problem/29716016 - Check that we properly enforce DI on `let`
// variables and class properties.
protocol P { }
extension P {
mutating func foo() {}
var bar: Int { get { return 0 } set {} }
}
class ImmutableP {
let field: P // expected-note* {{}}
init(field: P) {
self.field = field
self.field.bar = 4 // expected-error{{}}
}
}
func immutableP(field: P) {
let x: P // expected-note* {{}}
x = field
x.bar = 4 // expected-error{{}}
}