It appears that conditional casts require a check of the
type's metadata at runtime. There's no reason for us to
permit that at this time, since all such conditional
casts are going to fail, unless its the identity cast.
That is, a move-only type is currently only a subtype
of itself.
So for now, `is`, `as?`, `as!` casts from or to a
move-only type are now an error. The `as` casts
are permitted only if the two move-only types are
equal.
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.
For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.
The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
`OpaqueUnderlyingTypeChecker` should skip conditional availability
blocks if none of the conditions restrict the current target.
Resolves: rdar://103445432
Most of the diagnostics for extra/missing/mislabeled arguments refer
to argument to a "call". Some (but not call) would substitute in
"subscript". None would refer to an argument to a macro expansion
properly.
Rework all of these to refer to the argument in a call, subscript, or
macro expansion as appropriate. Fix up lots of tests that now say
"subscript" instead, and add tests for macro expansions.
An early approach to codegen for `#_hasSymbol` relied on the Darwin platfom SDK, but now that the feature lowers directly to NULL checks in LLVM IR a platform restriction is no longer needed.
However, the tests for `#_hasSymbol` remain unsupported on Windows since that OS does not support weak linking.
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`
The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.
rdar://102362022
Type checking of closure bodies does not invoke `TypeChecker::typeCheckStmtConditionElement()` so use of availability macros inside closure bodies written in fragile (inlinable) functions was undiagnosed. Move the diagnostic logic to `MiscDiagnostics.cpp` which implements diagnostics that are emitted regardless of the typechecking model used.
Additionally, remove the `DC->getAsDecl() != nullptr` check from `diagnoseHasSymbolCondition()` which was preventing similar fragile function diagnostics for `if #_hasSymbol` from being emitted when a closure was involved.
Resolves rdar://100581013
Fixes rdar://100872195 ( error: 'move' can only be applied to lvalues
error: Can not use feature when experimental move only is disabled!)
Identifiers with a single underscore are not reserved for use by the
language implementation. It is perfectly valid for a library to define
its own '_move'.
The contextual _move keyword should only be parse when it is followed by an lvalue, so should *not* conflict with user-defined '_move' functions.
https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md#source-compatibility
Revert "Remove properties from AST nodes"
This reverts commit e4b8a829fe.
Revert "Suppress more false-positive 'self is unused' warnings"
This reverts commit 35e028e5c2.
Revert "fix warning annotation in test"
This reverts commit dfa1fda3d3.
Revert "Permit implicit self for weak self captures in nonescaping closures in Swift 5 (this is an error in Swift 6)"
This reverts commit 94ef6c4ab4.
It's possible that TypeChecker::typeCheckStmt has did not propagate
`HadError` properly while checking the body of a function, so opaque
result checker has to be careful about requesting types from expressions.
Resolves: rdar://100066109
Replace the use of bool and pointer returns for
`walkToXXXPre`/`walkToXXXPost`, and instead use
explicit actions such as `Action::Continue(E)`,
`Action::SkipChildren(E)`, and `Action::Stop()`.
There are also conditional variants, e.g
`Action::SkipChildrenIf`, `Action::VisitChildrenIf`,
and `Action::StopIf`.
There is still more work that can be done here, in
particular:
- SourceEntityWalker still needs to be migrated.
- Some uses of `return false` in pre-visitation
methods can likely now be replaced by
`Action::Stop`.
- We still use bool and pointer returns internally
within the ASTWalker traversal, which could likely
be improved.
But I'm leaving those as future work for now as
this patch is already large enough.