`ExprRewriter::coerceToType` should canonicalize contextual type before
attempting to use it for value abstraction, because sugared type could
have typealias references that hide their underlying opaque result types.
Resolves: rdar://98577451
In some circumstances opened type might not have a fixed binding.
A good example could be dependent sub-component produced for
result builder transformed code (connected via one-way constraints),
in such a case `OpenedTypes` would have outer generic parameters
but they might not be bound yet, so they have to be printed as
type variables.
The outermost wrapper is the one at index `0` in the wrapper list
but it's easy for humans to make a reverse assumption since outermost
is the back of the list. Let's add a dedicated method to reduce error
probability of the property wrapper APIs.
If the type for such declaration could be completely inferred it
would be used during solution application. This is used to infer
types for result builder components.
Constraint generator records conversion between chain result expression
and contextual type as anchored on an implicit unresolved chain result,
which means that coercion has to do the same in case restrictions
(like Double<->CGFloat conversion) depend on locators to retrieve
information for the solution.
Resolves: rdar://97261826
Move the check where we insert UnderlyingToOpaqueExpr earlier in
coerceToType(). Otherwise, returning a metatype or function type
would attempt to perform a conversion instead of building a
UnderlyingToOpaqueExpr.
Fixes part of https://github.com/apple/swift/issues/60038.
Rather than only setting the isolated-by-preconcurrency bit during
constraint application, track the closures it will be set for as part
of the constraint system and solution. Then, use that bit when
performing "strict concurrency context" checks and type adjustments,
so we don't treat an inferred-to-by-`@Sendable`-by-preconcurrency
closure in the solver as if it weren't related to preconcurrency.
Fixes the spurious warning from
https://github.com/apple/swift/issues/59910.
Rather than re-using `DiagnosticBehavior` to describe how a fix should
act, introduce `FixBehavior` to cover the differences between (e.g.)
always-as-awarning and downgrade-to-warning. While here, split the
`isWarning` predicate into two different predicates:
* `canApplySolution`: Whether we can still apply a solution when it
contains this particular fix.
* `affectsSolutionScore`: Whether
These two predicates are currently tied together, because that's the
existing behavior, but we don't necessarily want them to stay that way.
The locator needs to much what was produced by constraint generator
otherwise Double<->CGFloat implicit coercion wouldn't be able to
find the overload choice.
Constraint generator records conversion between source and destination
types as anchored on an assignment, which means that coercion has to do
the same in case restrictions (like Double<->CGFloat conversion) depend
on locators to retrieve information for the solution.
Just like in case of array elements, the locator needs to much what
was produced by constraint generator otherwise Double<->CGFloat implicit
coercion wouldn't be able to find the overload choice.
The type checker is now permitting `@Sendable` closures whose captures
can be by-reference, because we do not error. Remove an aspirational
SIL verifier check that banned this.
When referring to a `@preconcurrency` function as a value, use the normal
type for the initial declaration reference and then introduce an
appropriate function conversion expression to the adjusted type.
Fixes more issues related to rdar://94597323.
When we have adjusted the type of a dynamic member reference (e.g.,
for `@objc optional` methods) due to `@preconcurrency` or similar,
form the original dynamic member reference based on the original type
and then introduce an appropriate conversion. This better reflects the
adjustment in the AST, eliminating a SIL verifier crash.
Fixes rdar://94597323.
Unfortunately current approach of making a conversion independent of location
doesn't work when conversion is required for multiple arguments to the
same call because solver expects that either there are no Double<->CGFloat
conversions, or one of them has already been applied which is not the case.
The reason why locations weren't preserved in the first place is due to
how a solution is applied to AST - AST is mutated first and then, if there
are any conversions, they are applied to the already mutated version of
original AST. This creates a problem for Double<->CGFloat which depends
on an overload choice of injected call and it's impossible to find it based
on the mutated AST. But it turns out that this is only an issue in two
specific cases - conversions against contextual type and after optional injection.
This situations could be mitigated by dropping parts of the locator which are
unimportant for the Double<->CGFloat conversion - anchor in case of contextual
and `OptionalPayload` element(s) in case of optional injection.
Resolves: https://github.com/apple/swift/issues/59374
Using `replaceCovariantResultType`, which looks through optionals, to
substitute the container type for the result type would add an extra
level of optionality to the result type whenever the container type was
`Optional`, causing a crash later in the game. Besides, we don't have to
do this in the first place, because we know these types match in the case
of an initializer (neglecting optionality).