Files
Allan Shortlidge 10e9c44de8 CSApply: Honor a pattern binding's explicit type annotation in its interface.
When applying a constraint system solution to a pattern binding initialization,
the type stamped onto the pattern was derived from the initializer expression
rather than from the type the solver assigned to the pattern itself. When an
explicit annotation and the initializer share a canonical type but differ in
sugar, coercing the initializer to the annotation type is a no-op that leaves
the initializer's own sugar in place, so the pattern and the VarDecl printed
into the .swiftinterface ended up with the initializer's sugar instead of the
written annotation.

This is mostly cosmetic, but it turns into a correctness problem when the
initializer's sugar names a typealias that isn't visible at the interface's
access level. For example, a public stored property annotated with a public
alias but initialized from an expression of an internal alias would print the
internal alias in the interface, producing a declaration that references a type
the interface can't see and breaking interface verification.

For typed patterns, use the pattern's solved type instead of the type derived
from the init. Assuming type checking is successful, the two types must share a
canonical type so this change only affects the printed sugar.

A better fix would be to unconditionally use the pattern's solved type,
regardless of whether the pattern is typed or not. Doing so causes some
regressions elsewhere, though, because the constraint solver does not currently
preserve typealias sugar on constructors everywhere it ought to. Using the
solved type for other kinds of patterns can therefore end up causing desugared
types to show up in more places where they aren't desirable.

Resolves rdar://178091149.
2026-06-04 10:50:07 -07:00
..
2024-08-08 19:35:00 +02:00
2024-08-08 19:35:00 +02:00
2024-08-08 19:35:00 +02:00
2024-10-31 11:32:40 +00:00
2024-10-31 11:32:40 +00:00