[6.0] Consistently treat let properties as immutable within the type checker #73664
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation: Rework our handling of let properties so that they are treated as rvalues uniformly except when they are being assigned to. This moves the inout/mutating checking up into the type checker, whereas it was previously handled at a later stage in Definite Initialization. This change allows overload resolution to correctly reject a call to a
mutable
function on alet
property in an initializer, and therefore choose another option, which is a more appropriate way to model the language semantics.Original PR: #73609
Radar/issue: rdar://127258363, a source compatibility issue with
AsyncIteratorProtocol.next()
's default implementation that required this semantic improvement.Risk: Medium-low. This changes the modeling of references to
let
instance properties within an initializer and uninitialized locallet
properties within the type checker to make them rvalues unless they're the target of an assignment (in which case they remain lvalues). The type checker, however, still creates an AST that treats them as lvalues (that are immediately loaded), because later compiler passes (SILGen and DI) expect this modeling. The overall effect is expected to be very small, and should only serve to make some ill-formed programs (where the type checker picked amutable
function on an lvalue) well-formed or diagnose in an earlier phase of the compiler.Reviewed by: @xedin