Commit Graph

4105 Commits

Author SHA1 Message Date
Slava Pestov
290701cb4d Sema: Ban shadowing generic parameters from outer scopes
Code like that is usually indicative of programmer error, and does not
round-trip through module interface files since there is no source
syntax to refer to an outer generic parameter.

For source compatibility this is a warning, but becomes an error with
-swift-version 6.

Fixes rdar://problem/108385980 and https://github.com/apple/swift/issues/62767.
2023-04-25 17:41:23 -04:00
Doug Gregor
067e4ec501 Merge pull request #65410 from DougGregor/macro-cycle-break-part-deux 2023-04-25 06:37:24 -07:00
Doug Gregor
5abb77d18d Improve cyclic reference diagnostics for macro resolution and expansion
We are likely to debugging more cyclic references involving macros in
the future, so improve the diagnostics to specify what operation we're
performing (e.g., macro resolution vs. expansion of a particular kind
of macro) and the macro name, when possible, so failures are easier to
diagnose. No functionality change for well-formed code.
2023-04-24 21:15:58 -07:00
nate-chandler
0c0ec72255 Merge pull request #65377 from nate-chandler/rdar108385761
[SILGen] Consuming a param implies it's eager-move.
2023-04-24 12:49:46 -07:00
Nate Chandler
525541fd1c [Sema] Ban @_eagerMove on Copyable things. 2023-04-21 21:59:31 -07:00
Alex Lorenz
346ba0153a Merge pull request #65338 from hyp/eng/enum-fix-indirect
[interop][SwiftToCxx] do not expose unsupported enums yet
2023-04-21 08:15:42 -07:00
Hamish Knight
017794a7d7 Merge pull request #65098 from hamishknight/poundland 2023-04-21 09:26:10 +01:00
Alex Lorenz
71ef7e8d3d [interop][SwiftToCxx] do not expose unsupported enums yet
This includes indirect enums, enums with multiple associated values, or enums whose associated value is a type we don't yet support
2023-04-20 18:05:00 -07:00
Joe Groff
8ea5ab84d3 Merge pull request #65173 from jckarter/noncopyable-tuples-not-supported
Diagnose attempts to use tuples with noncopyable elements.
2023-04-17 10:49:53 -07:00
Holly Borla
0ed4b3325f [SE-0393] Enable parameter packs for generic functions.
The VariadicGenerics flag still exists and is required for generic types
with parameter packs
2023-04-15 15:40:05 -07:00
Joe Groff
52e97d6544 Diagnose attempts to use tuples with noncopyable elements.
These aren't fully supported yet. rdar://108024586
2023-04-14 16:49:30 -07:00
Alex Lorenz
045fcf3ff5 [interop] Prohibit use of C++ APIs in public interfaces that opt-in into library evolution
The CxxStdlib overlay now has to be built without library evolution enabled.
2023-04-13 10:48:09 -07:00
Holly Borla
234b5dc660 [SE-0393] Require the repeat keyword for generic requirement expansions. 2023-04-12 22:04:01 -07:00
Hamish Knight
bca451baa0 [Sema] Improve diagnostic for empty if expr branch
Previously we would say that it must end with a
`throw`, but a more useful diagnostic is that
there is an expression missing.
2023-04-12 14:54:22 +01:00
Alex Lorenz
b60d635db7 [interop] make interop diagnostics more consistent with the rest of Swift diagnostics 2023-04-10 16:20:07 -07:00
Robert Widmann
8d709c4e80 Merge pull request #62151 from CodaFi/initial-orders
Deprecate Application-Specific Main Entrypoint Attributes
2023-04-09 14:05:13 -06:00
Robert Widmann
5c78c60588 Deprecate Application-Specific Main Entrypoint Attributes
Issue a deprecation warning in Swift 5 and an error in Swift 6 when we encounter @UIApplicationMain and @NSApplicationMain. These attributes are unnecessary now that @main works with UIApplicationDelegate and NSApplicationDelegate. As these conformances are required when working with the corresponding attributes, we can migrate users off of them by replacing them with @main.
2023-04-09 11:07:52 -06:00
Pavel Yaskevich
c7766763e8 Merge pull request #64846 from Rajveer100/branch-for-issue-53822
Improved Cast Diagnostics when Literals are involved
2023-04-07 20:31:58 -07:00
Rajveer
2c96e90c71 [Sema] Improved Cast Diagnostics when Literals are involved
Fixes Issue #53822
2023-04-07 00:18:02 +05:30
Allan Shortlidge
24a3317420 Merge pull request #64885 from tshortli/ban-unavailable-stored-properties
Sema: Ban unavailable stored properties
2023-04-04 22:27:50 -07:00
Richard Wei
01e6fe2936 [Macros] Code item macros
Add support for declaring and expanding code item macros.  Add experimental feature flag `CodeItemMacros`.
2023-04-04 09:54:57 -07:00
Allan Shortlidge
9812c90023 Sema: Ban unavailable stored properties.
Marking a stored property as unavailable with `@available` should be banned,
just like it already is banned for potential unavailability. Unavailable code
is not supposed be reachable at runtime, but unavailable properties with
storage create a back door into executing arbitrary unavailable code at
runtime:

```
@available(*, unavailable)
struct Unavailable {
  init() {
    print("Unavailable.init()")
  }
}

struct S {
  @available(*, unavailable)
  var x = Unavailable()
}

_ = S() // prints "Unavailable.init()"
```

Resolves rdar://107449845
2023-04-04 08:52:39 -07:00
Allan Shortlidge
0d23dc6346 Sema: Ban unavailable deinits.
Destructors are always called if declared, so allowing deinit to be declared as
unavailable (or potentially unavailable) creates a type checking loophole that
allows unavailable code to execute at runtime:

```
class C {
  @available(*, unavailable)
  deinit {
    print("Oops")
  }
}

_ = C() // prints "Oops"
```

Resolves rdar://106409012 and https://github.com/apple/swift/issues/63854.
2023-04-01 14:30:35 -07:00
Doug Gregor
49277f7e89 [Macros] Move most macro definition checking into ASTGen
In preparation for supporting macros that are defined in terms of other
macros, adopt macro definition checking provided by the
`MacroDeclSyntax.checkDefinition` operation (implemented in
swift-syntax). Use this in lieu of the checking on the C++ side.

This required me to finally fix an issue with the source ranges for
Fix-Its, where we were replacing the leading/trailing trivia of nodes
along with the node itself, even though that's incorrect: we should
only replce the node itself, and there are other Fix-It kinds for
replacing leading or trailing trivia.
2023-03-29 16:30:42 -07:00
Alexis Laferrière
d707dc4d81 Merge pull request #64516 from xymus/remark-transitive
[Serialization] Remark on transitive dependencies and loading requirement
2023-03-28 09:18:07 -07:00
swift-ci
8ac71b115c Merge pull request #64525 from beccadax/checkmate-ii
Re-merge #63668: Improve @objcImplementation member checking
2023-03-28 00:56:44 -07:00
Alexis Laferrière
bf2d2475f3 [Serialization] Remark on transitive dependencies 2023-03-27 10:04:03 -07:00
Doug Gregor
c31f6fa0cc Merge pull request #64631 from DougGregor/macro-parameter-defaults 2023-03-27 06:50:08 -07:00
Doug Gregor
9d9f8326c8 [Macros] Allow macro parameters to have default arguments.
SE-0382 allows macro parameters to have default arguments. Enable these
default arguments, with the normal type checking rules. One
significant quirk to this implementation is that the actual default
argument values don't make it to the macro implementation. This is a
previously-unconsidered design problem we'll need to address.

Tracked by rdar://104043987.
2023-03-26 22:13:37 -07:00
Ellie Shin
f87ba95d73 Warn if a package binary module is loaded from SDK
Resolves rdar://107074380
2023-03-25 17:09:10 -07:00
Becca Royal-Gordon
a2f1d357ca Refactor and expand @objcImpl checking
Create a checker for @_objcImplementation member implementations that considers all of a class’s interface and implementation decls at once. This allows us to handle several things better:

• Unimplemented requirements are now diagnosed

• Header members that can match several implementations, or implementations that could match several header members, are now diagnosed

• Tailored diagnostic when the implementation's Swift name matches the header's selector instead of its Swift name

• Recommends inserting `@objc(<selector>)` when a Swift name matches but the implicit ObjC name doesn't

• An `@objc(<selector>)` on one implementation can eliminate its requirement from being considered for other implementations, resolving ambiguities

This does unfortunately regress the diagnostics when a requirement is implemented in the wrong extension. Some sort of whole-module checking would be needed to address this problem.
2023-03-25 14:53:29 -07:00
Becca Royal-Gordon
3bcefc0731 Diagnose objcImpl members with wrong name 2023-03-25 14:52:40 -07:00
Becca Royal-Gordon
cf86fd4a73 Correct and improve objcImpl member matching
• `@objc` is now inferred on non-`final` members of @objcImplementation extensions
• Diagnostics now suggest adding `private` to ObjC helper members, not `@objc`, in line with currently proposed behavior
• Better diagnostic for members implemented in the wrong extension

Part of rdar://103150189.
2023-03-25 14:52:40 -07:00
Ellie Shin
c2bb890f63 Merge pull request #64488 from apple/es-load
Do not load modules of the same package if built from interface
2023-03-22 23:26:12 -07:00
Ellie Shin
fc2b61da71 - Do not load modules of the same package if built from interface.
- Show diagnostics with an interface path

Resolves rdar://104617990
2023-03-22 17:30:27 -07:00
Holly Borla
e78cf220c5 Merge pull request #64526 from hborla/invalid-repeat
[ConstraintSystem] Diagnose pack expansion expressions in non-variadic contexts.
2023-03-22 08:53:00 -07:00
Holly Borla
da3079de05 [ConstraintSystem] Diagnose pack expansion expressions in non-variadic contexts. 2023-03-21 21:58:05 -07:00
Allan Shortlidge
eb6dc2279a Merge pull request #64515 from tshortli/revert-more-available-than-unavailable-fixes
Sema: Don't diagnose declarations more available than unavailable container
2023-03-21 16:58:31 -07:00
Holly Borla
c60b4860ab Merge pull request #64498 from hborla/diagnose-pack-outside-expansion-expr
[ConstraintSystem] Enforce `TVO_CanBindToPack`, and diagnose pack references outside of pack expansion expressions.
2023-03-21 14:00:52 -07:00
Allan Shortlidge
620462ddf6 Sema: Don't diagnose declarations more available than unavailable container.
It turns out that we must allow declarations with `introduced:` availability
nested inside of other declarations that are `unavailable` in order to
influence weak linking. Stop diagnosing declarations as being more available
than their unavailable containers and revert some changes to availability
inference that were designed to avoid creating these nestings but caused
regressions for declarations marked `@_spi_available.`

Reverts parts of https://github.com/apple/swift/pull/64310,
https://github.com/apple/swift/pull/64015, and
https://github.com/apple/swift/pull/62900.
2023-03-21 13:55:05 -07:00
Sophia Poirier
8648753332 Merge pull request #64447 from sophiapoirier/pack_expansion_error_clarity
[Variadic Generics] distinctly diagnose more types of pack expansion errors
2023-03-21 12:31:46 -07:00
Holly Borla
cb19fc3a71 [ConstraintSystem] Enforce TVO_CanBindToPack, and diagnose pack references outside
of pack expansion expressions.
2023-03-20 20:13:48 -07:00
zoecarver
96d0b35048 [cxx-interop] Fixit: std.x -> CxxStdlib.x. 2023-03-20 16:14:42 -07:00
Sophia Poirier
19e671b5f2 [Variadic Generics] distinctly diagnose more types of pack expansion errors + add fixits 2023-03-20 15:51:19 -07:00
Rajveer
c34f099c7d Improved out-of-place binding diagnostic and reflecting 'var' or 'let' binding pattern
Fixes Issue #63993
2023-03-19 19:26:58 +05:30
Slava Pestov
7e5e7204b3 Merge pull request #64469 from slavapestov/more-variadic-generic-type-requirements
Checking requirements of variadic generic types (compile-time and runtime)
2023-03-18 09:36:02 -04:00
Konrad `ktoso` Malawski
e0877594da [Concurrency] Custom executors with move-only Job (#63569) 2023-03-18 14:02:43 +09:00
Slava Pestov
b6b51cf4cf AST: Checking of pack requirements 2023-03-17 22:18:55 -04:00
Ellie Shin
2bc92a6a59 Merge pull request #64408 from apple/es-inline
Allow @usableFromInline and @inlinable to package decls
2023-03-17 15:34:11 -07:00
Ellie Shin
ef321c9fd2 Allow @usableFromInline and @inlinable to package decls
Add tests for packgae inline
Add more package acl tests

Resolves rdar://104617133
2023-03-16 11:21:11 -07:00