Commit Graph

468 Commits

Author SHA1 Message Date
Pavel Yaskevich
25629bed20 [Diagnostics] Enhance property wrapper diagnostics with member kind 2019-06-28 14:37:21 -07:00
Sam Lazarus
70bdcfd370 Sema: Add handling for fixes when member is present on $$ version of decl 2019-06-28 12:09:50 -07:00
Sam Lazarus
bd54febb37 Sema: Change property wrappers fixit to always remove the correct number of '$' 2019-06-28 12:09:50 -07:00
Sam Lazarus
55b17feac1 Sema: Handle storage wrappers correctly in diagnostics 2019-06-28 12:09:49 -07:00
Sam Lazarus
6ec03da6b0 Sema: Add property wrapper diagnostic for unnecessary $ in member access
Additionally, refactor some of the logic for the original add $ diagnostic
so that a lot of logic can be shared between the two. Also rename the
original fix and diagnostic to better reflect their purpose.
2019-06-28 12:09:49 -07:00
Doug Gregor
db5440bdef [SE-0258] Rename wrapperValue to projectedValue. 2019-06-26 07:39:01 -07:00
Doug Gregor
7bb01c743b [SE-0258] Promote projection variables ($foo) to the original property access
When the outermost property wrapper associated with a property has a
`wrapperValue`, create the projection property (with the `$` prefix)
at the same access level as the original property. This puts the
wrapped-value interface and the projection interface at the same level.

The newly-introduced @_projectionValueProperty attribute is implicitly
created to establish the link between the original property and the
projection value within module interfaces, where both properties will
be explicitly written out.
2019-06-26 07:39:01 -07:00
Doug Gregor
446d0b3953 [SE-0258] Rename backing storage property to _foo.
In anticipation of upcoming changes to the property wrapper proposal,
rename the backing storage for a wrapped property to "foo", unconditionally.
2019-06-26 07:39:01 -07:00
Doug Gregor
22e40fedf5 [SE-0258] Enable default argument for wrapped property going through init().
My recent refactoring of default arguments for the memberwise initializer
accidentally dropped support for getting a default argument when the
attached property wrapper has an init(). Reinstate that support,
fixing rdar://problem/52116923.
2019-06-25 10:03:15 -07:00
Suyash Srijan
9f3cdb92b2 [Test] Update tests 2019-06-25 01:07:14 +01:00
Suyash Srijan
701a6ca84d [Typechecker] Look through all optional types when checking for Never 2019-06-24 20:44:31 +01:00
Sam Lazarus
ebcbaca968 [Diagnostics] Add a diagnostic for inserting a $ to remove an extraneous property wrapper unwrap (#25507) 2019-06-20 20:28:25 -04:00
Doug Gregor
1160017e9b [SE-0258] Escalate access of wrapperValue-produced $x to internal. 2019-06-14 11:49:18 -07:00
Doug Gregor
99d42c42b9 [SE-0258] Add a Fix-It for the value -> wrappedValue rename. 2019-06-14 01:13:24 -07:00
Doug Gregor
d35e1eaf72 [SE-0258] Support initial values & explicit initialization arguments.
Allow both explicit initialization and initial values to work together, e.g.,

```
@Clamping(min: 0, max: 255) var red: Int = 127
```

gets initialized as

```
Clamping(initialValue: 127, min: 0, max: 255)
```
2019-06-14 01:10:53 -07:00
Doug Gregor
99b40ba728 [SE-0258] Rename 'value' to 'wrappedValue'.
The latter name is far less likely to conflict. Maintain backward compatibility
by also accepting 'value' (with a warning).
2019-06-13 22:48:39 -07:00
Doug Gregor
8cc7f09bca [SE-0258] More tests and hardening for property wrapper composition 2019-06-13 22:32:49 -07:00
Doug Gregor
82ed5e9a02 [SE-0258] Implement basic support for property wrapper composition.
When multiple property wrapper attributes are provided on a declaration,
compose them outside-in to form a composite property wrapper type. For
example,

  @A @B @C var foo = 17

will produce

  var $foo = A(initialValue: B(initialValue: C(initialValue: 17)))

and foo's getter/setter will access "foo.value.value.value".
2019-06-13 18:26:29 -07:00
Doug Gregor
2e8d9a4331 [SE-0258] Adopt @propertyWrapper everywhere. 2019-06-12 13:09:40 -07:00
Doug Gregor
1e0e67106b [SE-0258] Warn about (but still use) 'delegateValue' in lieu of 'wrapperValue'.
Provide some backward compatibilty for property delegates written before
they became property wrapper, picking up 'delegateValue' (if present)
but warning about it.
2019-06-12 11:26:41 -07:00
Doug Gregor
c36683f253 [SE-0258] Add @propertyDelegate and @propertyWrapper aliases
Fixes rdar://problem/51591955.
2019-06-12 11:26:40 -07:00
John McCall
a183f762cd Address review feedback on the function-builders-on-funcs/vars patch. 2019-06-11 17:34:45 -07:00
John McCall
999d98acb1 Fix treatment of single-line getters with function builders.
rdar://50561122
2019-06-11 17:34:45 -07:00
John McCall
952eb9d8f9 Allow function-builder attributes on funcs and computed vars.
rdar://50150690
2019-06-11 17:34:45 -07:00
Doug Gregor
b7bbf4ca1a [Function builders] Allow uses of generic function builders.
Use the opened type from the callee declaration to open up references to
generic function builders that contain type parameters. This allows general
use of generic function builders.
2019-06-11 17:34:45 -07:00
John McCall
007842261f Rework the requests for getting a parameter's function-builder type.
Turn the generic CustomAttrTypeRequest into a helper function and
introduce a FunctionBuilderTypeRequest that starts from a ParamDecl.
This has better caching characteristics and also means we only need to
do a single cache lookup in order to resolve the type in the normal path.
It also means we don't need as much parameterization in the cache.

In addition, check that the parameter has function type in the request,
not just when late-checking the attribute, and add a check that it isn't
an autoclosure.
2019-06-11 17:34:44 -07:00
John McCall
2268939f3b Underscore _functionBuilder. 2019-06-11 17:34:44 -07:00
John McCall
93b3320196 Make getFunctionBuilderType() return a Type. 2019-06-11 17:34:44 -07:00
John McCall
15e7fa0983 Ignore unresolvable custom attributes in the function-builder checker. 2019-06-11 17:34:44 -07:00
John McCall
1e4f5f7750 Add @functionBuilder and check its applications to parameters. 2019-06-11 17:34:44 -07:00
Doug Gregor
5e00f01ce4 [SE-0258] Ensure that we fully check the property type vs. wrapper's value type
Various optimizations / shortcuts in type checking property wrappers meant
that we weren't consistently verifying that a wrapped property type is
identical to the type of the 'value' property of the wrapper. Do so.

Fixes SR-10899 / rdar://problem/51588022.
2019-06-11 10:06:31 -07:00
Doug Gregor
7fca8453b2 [SE-0258] Infer generic arguments of wrapper type from original property type
Implement the revised type inference rules that allow the type checker to
infer the generic arguments of a wrapper type from the original property type,
including in various structural positions. Fixes rdar://problem/51266744.
2019-06-02 23:38:46 -07:00
Doug Gregor
14de230adf Merge pull request #25188 from DougGregor/property-wrapper-wrapped-crash-on-invalid
[SE-0258] Fix crash-on-invalid involving some wrappers with wrapperValue
2019-06-01 07:55:40 -07:00
Doug Gregor
be2867fb84 [SE-0258] Fix crash-on-invalid involving some wrappers with wrapperValue
Fixes rdar://problem/51193573.
2019-05-31 21:50:21 -07:00
Doug Gregor
e009a1aa6d [SE-0258] Drop the lowercasing restriction on property delegate names. 2019-05-31 16:32:55 -07:00
Doug Gregor
59180db1f3 [SE-0258] Reduce access of backing storage variable to 'private'. 2019-05-30 10:37:34 -07:00
Doug Gregor
c02ecf9859 [SE-0258] Rename to Property Wrappers 2019-05-29 22:17:50 -07:00
Doug Gregor
1e2ef1baa7 [SE-0258] Ban get/set in properties with attached delegates. 2019-05-29 16:08:29 -07:00
Doug Gregor
5df8897b6f [SE-0258] Add a test for non-final properties with wrappers.
These were banned by the proposal, but not the implementation. Add a
test to make sure the two are in agreement.
2019-05-29 15:08:38 -07:00
Doug Gregor
af7b461db2 Merge pull request #24959 from DougGregor/non-objc-dynamic-everywhere
Allow non-@objc ‘dynamic’ in all language modes.
2019-05-21 15:05:52 -07:00
Doug Gregor
22c0995046 Allow non-@objc ‘dynamic’ in all language modes.
Non-‘@objc’ ‘dynamic’ has been allowed since Swift 5, but there’s no
reason to tie it to the language mode (Swift >= 5).

Fixes rdar://problem/50348013.
2019-05-21 13:40:04 -07:00
Doug Gregor
d86907e095 [Property delegates] Fix crash involving generic uses of delegateValue.
Fixes rdar://problem/50873275.
2019-05-20 10:15:12 -07:00
Doug Gregor
90859ad6aa [Type checker] Fix assertion/spin with ill-formed property delegate initialization
Fixes rdar://problem/50822051.
2019-05-15 16:42:38 -07:00
Doug Gregor
bf2c4d951b Prevent less-visible properties with delegates from affecting memberwise initializer
When a property with an attached delegate has less-than-internal visibility
and is initialized, don’t put it into the memberwise initializer because
doing so lowers the access level of the memberwise initializer, making it
fairly useless.

Longer term, it probably makes sense to have several memberwise initializers
at different access levels, so adding an initialized `private var` make
the memberwise initializer useless throughout the rest of the module.

Addresses rdar://problem/50266245.
2019-05-01 14:10:56 -07:00
Sam Lazarus
3d9b6396a1 Merge pull request #24059 from sl/sl/sr-10293
Allow var / let as parameter names but provide a warning and fixit to add backticks.
2019-04-26 09:30:23 -04:00
Sam Lazarus
ede8127adf Test: Add and update tests for allowing var and let as argument labels 2019-04-26 04:08:27 -04:00
Pavel Yaskevich
d5fcf1a665 Merge pull request #24274 from theblixguy/fix/computed-prop-fix-it-lazy
[CSDiagnostics] Removes lazy when applying computed property fix-it
2019-04-25 13:22:25 -07:00
Suyash Srijan
20cfa14423 [CSDiagnostics] Removes lazy attributes when applying computed property fix-it 2019-04-25 17:59:07 +01:00
nate-chandler
155a155000 Merge pull request #23251 from nate-chandler/nate/omit-return
Allow return to be omitted from single expression functions.
2019-04-25 08:36:34 -07:00
Doug Gregor
0c26e4349e Underscore the @propertyDelegate attribute to indicate that it's experimental 2019-04-24 21:25:33 -07:00