My work to type-check interpolations via conjunctions to improve code completion ([WIP] Migrate the remaining completion kinds to solver-based + rework type-checking of string interpolations by ahoppen · Pull Request #63717 · apple/swift · GitHub) uncovered a hole in self
capture checking.
Consider the following example:
func capture<T>(_: @escaping @autoclosure () -> T) {}
class Test { var value: Int = 0 func test() {
capture(value) }
}
Because Test
is a reference type we don't actually allow value
to be used without explicit self.
in an escaping autoclosure:
error: reference to property 'value' in closure requires explicit use of 'self' to make capture semantics explicit
capture(value) }
^
note: reference 'self.' explicitly
capture(value) }
^
self.
But if I wrap value in string interpolation like this:
capture("\(value)")
Expression type-checks successfully.
This is due to the fact that string interpolations are currently type-checked separately from context (just like multi-statement closured used to be) which means that MiscDiagnostics doesn't see synthesized "AutoClosureExpr" that wraps TapExpr
.
Type-checking interpolations together with the context would actually result in an error just like capture(value)
does which is a source compatibility regression.
So the question I want to raise here is whether this is an acceptable break, or I'd need to run a proposal clarification through evolution?