Commit Graph

974 Commits

Author SHA1 Message Date
Allan Shortlidge
8a9eb40965 Sema: Reject #_hasSymbol conditions in inlinable code. 2022-10-13 21:00:24 -07:00
Cal Stephens
22e43136d9 Enable SE-0365 behavior in Swift 5.8 2022-10-10 08:03:03 -07:00
Allan Shortlidge
64e8a0334d Sema: Diagnose if #_hasSymbol as unsupported on non-Darwin targets. 2022-10-08 00:09:34 -07:00
Andrew Trick
19175926da Disable '_move' contextual keyword absent -enable-experimental-move-only
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
2022-10-06 16:33:26 -07:00
Pavel Yaskevich
1a79d93121 Merge pull request #40702 from calda/cal--implicit-weak-self
[SE-0365] Allow implicit self for `weak self` captures
2022-09-30 10:30:57 -07:00
Allan Shortlidge
f810eb0818 Merge pull request #61316 from tshortli/accept-has-symbol-in-closures
Sema: Accept `if #_hasSymbol()` conditions in closure contexts
2022-09-30 09:02:35 -07:00
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03:00
Allan Shortlidge
8729801eb4 Sema: Store an 'invalid' bit in PoundHasSymbolInfo to avoid repeated if #_hasSymbol diagnostics. 2022-09-29 11:47:30 -07:00
Allan Shortlidge
034e53ad20 Sema: Accept if #_hasSymbol() conditions in closure contexts.
Resolves rdar://100129165
2022-09-29 10:55:08 -07:00
Cal Stephens
5bfdfd822c Only enable SE-0365 in Swift 6 2022-09-28 19:35:26 -07:00
Cal Stephens
cc92f76a9e Revert changes for handling SE-0365 in Swift 5
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.
2022-09-28 17:44:02 -07:00
Cal Stephens
e4b8a829fe Remove properties from AST nodes 2022-09-28 06:24:42 -07:00
Cal Stephens
35e028e5c2 Suppress more false-positive 'self is unused' warnings 2022-09-26 09:28:22 -07:00
Cal Stephens
94ef6c4ab4 Permit implicit self for weak self captures in nonescaping closures in Swift 5 (this is an error in Swift 6) 2022-09-25 14:32:19 -07:00
Pavel Yaskevich
1c0e887e5f [MiscDiagnostics] OpaqueChecker: Double-check validity of last expression
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
2022-09-23 09:36:23 -07:00
Cal Stephens
5946c66962 Style updates 2022-09-23 07:09:52 -07:00
Cal Stephens
9dd56f9daf Move remaining logic in LookupResultEntry::getBaseDecl() to ASTScope::lookupUnqualified impl, add more extensive tests, fix failing tests 2022-09-22 11:04:08 -07:00
Cal Stephens
4abca2bc9e Merge tag 'swift-DEVELOPMENT-SNAPSHOT-2022-09-12-a' of github.com:apple/swift into cal--implicit-weak-self
Tag build swift-DEVELOPMENT-SNAPSHOT-2022-09-12-a
2022-09-20 06:58:38 -07:00
Cal Stephens
84896edaf2 Use Ctx.Id_self and update comments 2022-09-15 20:01:40 -07:00
Hamish Knight
4716f61fba [AST] Introduce explicit actions for ASTWalker
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.
2022-09-13 10:35:29 +01:00
Pavel Yaskevich
149e57a0cb Merge pull request #60893 from calda/cal--warn-redundant-comparison-to-optional.none-case
Add warning when comparing a non-optional value to `Optional.none`
2022-09-12 00:36:24 -07:00
Cal Stephens
9167a177cc Merge branch 'main' into cal--implicit-weak-self 2022-09-11 10:24:55 -07:00
Slava Pestov
da76e1ee71 Sema: Allow one-element tuples when -enable-experimental-variadic-generics is on 2022-09-10 00:26:43 -04:00
Cal Stephens
d9be4a7213 Update check for Optional.none 2022-09-09 08:41:31 -07:00
Pavel Yaskevich
86e633197d Merge pull request #60895 from LucianoPAlmeida/fix-magic-literal
[Sema] Fix dictionary duplicate keys false positives for #line and #column magic literal
2022-09-01 13:34:24 -07:00
Cal Stephens
c3e74e06b4 Use a single warning, but dynamically specify 'nil' or 'Optional.none' 2022-09-01 09:10:01 -07:00
Cal Stephens
c2bf0f943e Revert "Combine the two diagnostics"
This reverts commit 2e7656218e.
2022-09-01 08:11:46 -07:00
Cal Stephens
568549f2c3 Update comment 2022-09-01 06:38:58 -07:00
Cal Stephens
2e7656218e Combine the two diagnostics 2022-09-01 06:23:42 -07:00
Luciano Almeida
568b949e09 [Sema] Fix dictionary duplicate keys false positives for #line and #column magic literal 2022-09-01 01:41:13 -03:00
Cal Stephens
ded9b78d25 Warn on redundant comparison to 'Optional.none', like we already do for 'nil' 2022-08-31 18:00:57 -07:00
Slava Pestov
40c2678e38 Sema: Fix existential opening for arguments to self.init/super.init delegation
Fixes rdar://problem/98404682.
2022-08-24 00:24:55 -04:00
Evan Wilde
fe309fc6b9 Move completion handler usage to availablity
The completion handler async replacement moved from being its own
attribute to being an availability attribute. This patch moves the
checking from being its own pass to being part of the availability
checking under the async availability checking diagnostic pass.
2022-08-19 22:31:38 -07:00
Anthony Latsis
5bfef4fc4b Merge pull request #60323 from simanerush/collection-literal-bug-fix
Sema: Emit diagnostics when walking into collection literals with defaulted types
2022-08-16 23:09:57 +03:00
Sima Nerush
f608802cfe Sema: Emit diagnostics when walking into collection literals with defaulted types
Resolves https://github.com/apple/swift/issues/60011

Gardening: clean up `checkTypeDefaultedCollectionExpr` function
2022-08-15 22:45:21 -06:00
Luciano Almeida
ee20fec382 [Sema] Warn about dictionary literal of dictionary type about duplicated keys 2022-08-15 22:54:55 -03:00
Michael Gottesman
f3081d0e9a [move-keyword] Put the move keyword behind the experimental move only flag for now.
Originally move when it was in the stdlib as _move was behind a keyword but we
moved it in front to allow for some testing. Now that we are going with a
keyword (which we can't leave in/deprecate) move it behind the move only
experimental flag until this gets through evolution.
2022-08-10 12:45:17 -07:00
Michael Gottesman
7da2c92358 [move-function] Ban move being passed non-declref expr values.
I did this by requiring this in the typechecker. This will ensure that when we
emit a move, we are guaranteed to have a value decl ref that we can evaluate. It also ensures that we can't _move fields.

auto
2022-08-08 12:50:42 -07:00
Pavel Yaskevich
498721c9df [TypeChecker] SE-360: Add support for if #unavailable
Lift a temporary restriction and make `if #available`
and `if #unavailable` behave consistently.
2022-07-20 13:26:43 -07:00
Pavel Yaskevich
225341e3d2 [Decl] Start storing and serializing "unavailability" bit per condition 2022-07-20 13:26:43 -07:00
Cal Stephens
778a2fc1f5 Merge branch 'main' into cal--implicit-weak-self 2022-07-18 10:00:23 -07:00
Slava Pestov
5c412b4b55 Sema: Don't allow opaque return types to reference DynamicSelfType
This cannot be represented in the ABI because we expect that the
opaque return type can be instantiated from the generic arguments
of its declaring context. Reconstructing type metadata for the
DynamicSelfType would require opaque return type instantiation
to also take the self *value*.

Fixes rdar://72407668 / https://github.com/apple/swift/issues/56367
2022-07-14 11:07:52 -04:00
Holly Borla
429488f6c9 [Sema] Use ExistentialType for Any and AnyObject. 2022-06-17 18:29:15 -07:00
Pavel Yaskevich
b7860ea055 [TypeChecker] Split for-in sequence into parsed and type-checked versions 2022-05-30 23:17:41 -07:00
Pavel Yaskevich
9fa39e94cf [MiscDiagnostics] Unhandled throw check should use recorded conformance
Use a conformance reference recorded in a `ForEachStmt` by
the type-checker, instead of trying to look it up again.
2022-05-30 23:17:41 -07:00
Allan Shortlidge
60146b32b4 Sema: Accept existentials without any in swiftinterfaces.
Resolves rdar://93052306
2022-05-10 17:43:05 -07:00
Hamish Knight
c5a53ef73e [Sema] Don't warn on trailing closures in closure conditions
Add ClosureExpr to the list of expressions we don't
walk into for the purposes of diagnosing trailing
closures in conditional initializers.

rdar://92521618
2022-04-29 14:47:19 +01:00
Moritz Dietsche
5d55ffea51 [lib/Sema] Suggest return when the last statement would be a valid … (#42415)
* [lib/Sema] Suggest `return` when the last statement would be a valid return value

Addresses SR-10988. When a multi-statement function body contains no return keyword but the last statement would be a valid return value, the compiler currently proposes a fixit to add the return keyword.
This changes extends this behavior to functions with opaque return types.
2022-04-23 10:56:12 -07:00
Josh Soref
4c77c59269 Spelling sema (#42474)
* spelling: accessibility

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: accessories

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: adjustments

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: all

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: ambiguous

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: arguments

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: assignment

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: associated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: assumes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: auxiliary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: availability

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: available

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: belongs

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: checking

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: clazz

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: compatibility

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: completely

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: completion

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: complicated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conformance

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: constrained

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: constraint

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: contextual

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conversion

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: convertible

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: couldn't

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: declaration

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: defaultable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dependent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: depending

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: describe

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: diagnostic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: diagnostics

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: existential

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: expects

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: explicit

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: explicitly

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: expression

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: first

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: font

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: forward

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: generation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: generic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: given

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: global

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: guarantee

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: happened

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: hierarchy

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: identical

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: immediately

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: implicit

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: indicates

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: inferred

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initializer

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: integrity

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interpolation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: introducing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: involved

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: just

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: like

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: likewise

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: mismatch

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: missing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: more

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: necessarily

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: noescape

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: nonetheless

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurrences

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: operators

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: optional

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: otherwise

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: outside

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: overload

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: overridden

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: override

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameter

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameters

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: penalize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: platforms

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: precedence

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preemptively

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preliminary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preserve

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: propagate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: propagated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: qualifier

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: question

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: really

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: received

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: references

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: replaceable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: replacement

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: representable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: representative

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: requirement

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: requires

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: resolved

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: retrieve

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rewriting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: satisfied

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: semantics

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: signature

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: similar

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: simplest

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: simplification

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: solver

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: struct

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: structurally

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: success

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: sure

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: symmetric

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: syntactically

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: target

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: that

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: themselves

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: these

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: this

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transform

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transparent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: tread

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: truncation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: type

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unconstructable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: universally

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unknown

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unwrapped

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: versioned

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: visible

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: where

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-20 15:12:46 -07:00
Pavel Yaskevich
1c426a30d1 Merge pull request #42484 from xedin/drop-se-0326-flag
[TypeChecker] NFC: Remove `-experimental-multi-statement-closures` flag
2022-04-20 14:39:35 -07:00