When the type checker noticed that a declaration with application extension
availability markup was used somewhere that it would be potentially unavailable
at runtime, the fix-it emitted by the compiler would check for the application
extension platform's availability:
```
if #available(macOSApplicationExtension 12, *) {
// Use potentially unavailable declarations
}
```
This runtime check won't work. The fix-it should just suggest checking the
availability of the base, non-extension platform instead.
Resolves rdar://125860317.
Just like other members of that type, `isPassedToSendableParameter` bit
set tracks information per parameter. The "passed" bit is applicable
to the argument rather than the parameter itself so it should bit kept
on the `AbstractClosureExpr`.
Given the following test case, override availability checking produced an
erroneus diagnostic:
```
@available(macOS 10.15, *)
protocol P {
associatedtype A
var a: A { get set }
}
@available(macOS 13.0, *)
protocol Q: P {
// error: overriding _modify accessor for 'a' must be as available as
// declaration it overrides
var a: A { get set }
}
```
The synthesized `_modify` accessor in `Q` is explicitly marked available in
macOS 13, which is less available than the `_modify` accessor in `P`. The
availability of `Q` should limit the required availability of the override and
prevent the diagnostic, but the implementation had a bug where it checked the
availability of the context's type instead of the contextual self type's
declaration. In the example, the context's type is `Self` which does not have
annotated availability.
Resolves rdar://133573707.
When referencing a declaration, check whether any of the types in that
reference are unsafe. This can diagnose cases where the original
declaration either wasn't actually unsafe, or is being provided with
unsafe types via generics.
Allow any declaration to be marked with `@unsafe`, meaning that it
involves unsafe code. This also extends to C declarations marked with
the `swift_attr("unsafe")` attribute.
Under a separate experimental flag (`DisallowUnsafe`), diagnose any
attempt to use an `@unsafe` declaration or any unsafe language feature
(such as `unowned(unsafe)`, `@unchecked Sendable`). This begins to
define a "safe" mode in Swift that prohibits memory-unsafe constructs.
Consolidate code related to determining which kinds of diagnostics to emit and
platform names to display so that it is not duplicated between regular
declaration diagnostics and conformance diagnostics.
NFC.
In this PR i worked on replacing the word accessor in diagnostics with more user-facing terminologies like setter, getter, didSet Observer, and members based on the context of the message.
in some messages i didn't need to pass DescriptiveDeclKind instead i just changed the text copy itself.
i also updated tests, so you might find it easier to check my changes this way.
Please let me know if there's something i should've done in a better way, and request changes if needed. !
i can squash my commits after reviewing getting the PR Reviewed, just to make it easier to be checked commit by commit
Resolves#55887
`fixDeclarationObjCName()` accepted optional selectors, but crashed if they were None. Make these parameters non-optional, treat an invalid `targetName` selector as “no name”, and adjust callers to pass non-optional values.
Re-enables decl/ext/objc_implementation.swift, which was disabled due to this bug.
Fixes rdar://128683206.
Impose the same limit we impose on other
forms of control flow statements (e.g `break`,
`continue`, `return`), where it cannot transfer
control out of the expression. This fixes a crash
where we'd fail to find a fallthrough nested in an
`if` expression. It is technically source breaking,
as we would have allowed the case where the `if`
expression is a directly nested result of an outer
`switch` expression, but I would be very surprised
if anyone is relying on that.
rdar://133845101
Allow `fallthrough` to appear as the last statement
in the case of a `switch` expression. We already
allowed it in other positions, this was just an
oversight.
rdar://127670432
I don't think this currently matters, but ensure
we re-contextualize BreakStmts and ContinueStmts
in RecontextualizeClosures since these statements
store DeclContexts.
`@unknown default` in switch statements are required for resilient enums since they
might be modified with new fields in the future and modules defining the enums are
generally not built together with the consuming modules.
However, if the modules are in the same package, they are required to be built together,
thus the requirement for `@unknown default` can be skipped. This PR removes the need for
that, enabling less boilerplate. Note this change only impacts typecheck and not SIL gen.
Resolves rdar://130015149.
If `OverriddenDeclsRequest` fails to find any overridden declarations, query
again ignoring missing imports to find declarations that were excluded due to the
`MemberImportVisibility` feature being enabled.
When `MemberImportVisibility` is enabled, if the import that would bring a
member declaration into scope is missing it is diagnosed as an error. The
existing resilience diagnostics that would also diagnose the same problem in
contexts that are visible in the module interface are therefore superflous with
the feature enabled.