Commit Graph

468 Commits

Author SHA1 Message Date
Suyash Srijan
370f47c27a [PropertyWrappers] Merge 'findDefaultInit' and 'findInitialValueInit' methods into a single 'findSuitableWrapperInit' method 2019-10-11 22:25:46 +01:00
Suyash Srijan
e41d1efb43 [PropertyWrappers] Try to find the best default value initializer if we have multiple inits, before diagnosing them as ambiguous 2019-10-11 22:25:46 +01:00
Suyash Srijan
ab31a0d3e9 [PropertyWrappers] Allow constructors with default arguments to be found by findDefaultInit() 2019-10-11 22:25:46 +01:00
Pavel Yaskevich
bc1a3eaaa5 Merge pull request #27584 from xedin/extend-use-of-single-param-splat-fix
[Diagnostics] Extend single parameter tuple splat to support generic parameters
2019-10-09 12:44:22 -07:00
Pavel Yaskevich
51476cde58 [Diagnostics] Clarify tuple splat message when single parameter is generic parameter
Since it's hard to say whether tuple use is really intended, let's
add `did you mean to pass a tuple?` note to the error message.
2019-10-09 10:58:31 -07:00
Pavel Yaskevich
7e6b4e4d57 [Diagnostics] Extend single parameter tuple splat to support generic parameters
Currently single parameter tuple splat fix/diagnostic supports only
cases where parameter is a concrete tuple type, let's enhance that to
support generic parameters as well e.g.:

```swift
func foo<T>(_: T) {}
foo(0, 1, 2) // `T` expects arguments to form a tuple e.g. `foo((0, 1, 2))`
```
2019-10-08 18:11:48 -07:00
Slava Pestov
a260d0a445 AST: getInterfaceType() returns ErrorType instead of Type() on circularity 2019-10-08 01:37:09 -04:00
Doug Gregor
81c0a0ea93 [Property wrappers] Allow init(wrappedValue:) initializers with defaulted args
Generalize the type checking when searching for "wrappedValue"
initializers to also allow initializers that have other, defaulted
parameters as well.
2019-09-24 09:11:53 -07:00
Doug Gregor
5431efab71 Add fixed test case from rdar://problem/53349209 2019-09-24 09:11:53 -07:00
Suyash Srijan
b3d3ef3867 [Test] Adds a test case 2019-09-18 01:58:24 +01:00
Hamish Knight
58459e7439 [CS] Allow simplification of key path subscript arg locators (#27194)
[CS] Allow simplification of key path subscript arg locators
2019-09-17 14:28:59 +01:00
Suyash Srijan
0bd7621a6b Merge pull request #27198 from theblixguy/fix/SR-11478
[PropertyWrapper] Fix a bug with static property wrapper being rejected in a class
2019-09-17 10:10:04 +01:00
Suyash Srijan
7ff3fd1f66 [Test] Adds some tests 2019-09-17 00:51:54 +01:00
Hamish Knight
176969ddde [CS] Allow simplification of key path subscript arg locators
This allows a few fixes to properly emit
diagnostics for key path subscript argument
contextual failures.

Resolves SR-11476.
2019-09-15 21:39:32 +01:00
Pavel Yaskevich
88c39db0c3 [Diagnostics] NFC: Fix improved test-cases related to argument-to-parameter mismatches 2019-09-13 22:35:53 -07:00
Doug Gregor
9ce12ac422 [Type checker] Compute "mutating" for projected variables of wrapped properties
Extend the recently-refactored logic for determining whether the
getter/setter for a wrapped property is "mutating" to also consider
the projection variables (e.g., $foo). Fixes SR-11393 /
rdar://problem/54839570.
2019-09-10 16:38:12 -07:00
Suyash Srijan
acba675326 [Test] Add more test cases as requested 2019-08-30 19:02:03 +01:00
Suyash Srijan
094869555e Merge branch 'master' into fix/SR-11288 2019-08-28 02:27:44 +01:00
Suyash Srijan
0ba003d327 [Test] Adds a test case 2019-08-22 23:54:11 +01:00
Doug Gregor
b4e80cfd90 [Constraint graph] Enable one-way constraints in function builders.
Enable one-way constraints by default for function builders, finishing
rdar://problem/50150793.
2019-08-19 22:49:15 -07:00
Pavel Yaskevich
c67cf88b7d [Diagnostics] Don't crash when gathering info about property wrapper in l-value base
Make `TypeBase::getTypeOfMember` more resilient to base type
being either an l-value (which we can look through), or an
error type - in such can it would return immediately.

Resolves: rdar://problem/54184846
2019-08-12 16:50:30 -07:00
Slava Pestov
2ef101c815 Sema: Don't add local functions to TC.definedFunctions
Instead, check them and their error handling right away.

In addition to fixing the crash in the radar, this also causes
us to emit unused variable warnings in functions containing
local functions.

Eventually, TC.definedFunctions should go away altogether.

Fixes <rdar://problem/53956342>.
2019-08-07 00:37:21 -04:00
Slava Pestov
1ee2db4520 AST: Accessors no longer appear as members of their parent DeclContext
Accessors logically belong to their storage and can be synthesized
on the fly, so removing them from the members list eliminates one
source of mutability (but doesn't eliminate it; there are also
witnesses for derived conformances, and implicit constructors).

Since a few ASTWalker implementations break in non-trivial ways when
the traversal is changed to visit accessors as children of the storage
rather than peers, I hacked up the ASTWalker to optionally preserve
the old traversal order for now. This is ugly and needs to be cleaned up,
but I want to avoid breaking _too_ much with this commit.
2019-07-30 15:56:00 -04:00
Joe Groff
fa4dd15612 Sema: Correct composition of property wrappers.
Fixes rdar://problem/53407949 | SR-11138. Previously, we'd only look at the outermost property wrapper to decide whether the wrapped property's getter and setter were `mutating` (or exist at all). In reality, this requires considering the semantics of the composed accesses of each wrapper layer's
`wrappedValue` property. Fixing this systematically addresses a number of issues:

- As SR-11138 reported, composing a nonmutating-get-set wrapper ought to produce a composed wrapper
  that's nonmutating.

- We would previously allow a property wrapper with a mutating getter to be nested inside one with
  only a getter, even though the resulting implementation was unsound (because there's no mutable
  context for the inner wrapper to execute its get on.)

- Similarly, we would construct unsound setters in cases where the setter can't exist, such as when
  the nested wrapper isn't settable but the outer wrapper is.
2019-07-26 16:09:54 -07:00
Joe Groff
1446b60801 Reenable property wrapper composition.
This reverts commit 5e08f7da32.
2019-07-25 15:50:21 -07:00
Slava Pestov
8047ddae82 Sema: Move finishStorageImplInfo() to StorageImplInfoRequest evaluation
This merges Sema's special logic for updating the ImplInfo of lazy properties
and property wrappers with the StorageImplInfoRequest.

I had to move some code from the parser into the StorageImplInfoRequest, to
avoid request cycles caused by hasStorage() calls; this is the right thing to
do anyway.

Since hasStorage() now answers false for lazy properties and property wrappers,
we have to move some diagnostic checks from checkDeclAttributesEarly() to
the StorageImplInfoRequest implementation itself.

Over time, I expect all of the checks currently in checkDeclAttributesEarly()
and checkDeclAttributes() to either migrate to requests, or typeCheckDecl().
2019-07-23 22:00:31 -04:00
Joe Groff
03dcccb828 Merge pull request #26287 from jckarter/disable-property-wrapper-composition
Disable property wrapper composition.
2019-07-23 12:39:12 -07:00
Joe Groff
5e08f7da32 Disable property wrapper composition.
There are ABI-affecting bugs with composition like SR-11138, so disable until those bugs can be
fixed. rdar://problem/53428736
2019-07-22 19:50:01 -07:00
Slava Pestov
a532a325e1 AST: Move a few methods from VarDecl down to ParamDecl 2019-07-22 20:19:09 -04:00
swift-ci
05d2ef22b8 Merge pull request #26246 from DougGregor/property-wrapper-crash-fixes 2019-07-19 16:21:35 -07:00
Doug Gregor
0df29877ed [SE-0258] Fix source locations for implicitly-generated initializer calls.
Fixes rdar://problem/52969503, a crash due to missing source location
information in implicitly-generated calls.
2019-07-19 10:15:28 -07:00
Suyash Srijan
f47f5c44e4 [CSDiag] Adds a new diagnostic for implicit propertyWrapper initializer 2019-07-18 23:06:03 +01:00
Suyash Srijan
1d18a3b668 [Test] Adds a test case 2019-07-18 21:40:18 +01:00
Doug Gregor
03c0cbc4ab [SE-0258] Remove compatibility with the first revision of the proposal
No longer recognize delegateValue or value as special properties in
a property wrapper type.
2019-07-10 15:29:12 -07:00
Doug Gregor
9a444242fb [SE-0258] Fixups for various renames of property wrappers. 2019-07-10 15:28:24 -07:00
Doug Gregor
1284878ad8 [SE-0258] Rename init(initialValue:) --> init(wrappedValue:).
Addresses core team decision on acceptance of property wrappers.

Fixes rdar://problem/48871069.
2019-07-10 14:26:53 -07:00
Doug Gregor
3954a4a57b Merge pull request #26043 from DougGregor/property-wrappers-top-level-error
[SE-0258] Diagnose uses of property wrappers in top-level code.
2019-07-09 20:36:12 -07:00
Doug Gregor
ee52e7317c [SE-0258] Don't ask for the nominal type decl of an unresolved property wrapper
Generic type aliases break this query; don't use it.
Fixes rdar://problem/51989272
2019-07-09 16:36:19 -07:00
Doug Gregor
02ff2ee4e6 [SE-0258] Diagnose uses of property wrappers in top-level code.
We don't current support property wrappers at the top level, so
error on them (rather than crashing later).
Fixes rdar://problem/51538524.
2019-07-09 16:30:35 -07:00
Doug Gregor
a66a5ff0a4 [SE-0258] Properly contextualize closures in property wrapper initialization.
Fixes SR-11061 / rdar://problem/52593304 / rdar://problem/52220881.
2019-07-08 16:39:49 -07:00
Pavel Yaskevich
c195fdcc5c [Diagnostics] NFC: Add more test-cases for subscript refs with unintended property unwrap 2019-07-05 15:23:48 -07:00
Pavel Yaskevich
626b93cca2 [ConstraintSystem] Make sure that property wrapper diagnostics don't consider invalid declarations 2019-07-04 20:01:19 -07:00
Pavel Yaskevich
1c161e7109 [Diagnostics] Extend property wrapper diagnostics to support subscript refs
Previously unintended property wrapper unwrap diagnostics supported only
dot expressions, let's extend it to cover subscripts as well.
2019-07-03 22:13:31 -07:00
swift-ci
09a3147d31 Merge pull request #25719 from theblixguy/fix/SR-10995 2019-07-02 22:09:01 -07:00
Pavel Yaskevich
7a0b8950cc Merge pull request #25904 from xedin/dont-fix-wrapper-if-generic-args-didnt-line-up
[ConstraintSystem] Don't try fixes while matching types for property …
2019-07-01 11:19:50 -07:00
Doug Gregor
3faf0e8d18 Merge pull request #25884 from DougGregor/property-wrappers-enclosing-self
[Property wrappers] Prototype support for enclosing self-based access
2019-07-01 07:05:57 -07:00
Pavel Yaskevich
f7913f869e [ConstraintSystem] Don't try fixes while matching types for property wrapper diagnostics
While trying to figure out whether there is a missing or extraneous
property wrapper reference, let's not try to fix any generic argument
mismatches associated with wrapper or wrapped types, otherwise the
fix is going to be incorrect.
2019-07-01 00:27:38 -07:00
Sam Lazarus
0cf1bf2b7e [Diagnostics]: Add diagnostics for incorrect property wrapper references in function args (#25889) 2019-06-30 12:42:53 +02:00
Doug Gregor
bc2e605b31 [Property wrappers] Improve enclosing-self subscript handling.
Extend handling of enclosing-self subscripts by differentiating
between the original wrapped property (which now goes through
`subscript(_enclosingInstance:wrapped:storage:)`) and the projected
property (which goes through
`subscript(_enclosingInstance:projected:storage:)`). The new middle
argument provides a key path to the property that was accessed,
allowing one to distinguish the property being updated.
2019-06-29 23:22:01 -07:00
Doug Gregor
8c54db727b [Property wrappers] Prototype support for enclosing self-based access
Allow property wrapper types to support a second access pattern for
instance properties of classes. When supported, the property wrapper's
static subscript(_enclosingInstance:storage:) is provided with the
enclosing "self" and a reference-writable key path referring to the
backing storage property.

Implements rdar://problem/52222560.
2019-06-29 00:08:49 -07:00