Commit Graph

468 Commits

Author SHA1 Message Date
Holly Borla
66e85721cb Merge pull request #30807 from hborla/property-wrapper-refactoring
[Property Wrappers] Refactor property wrappers so the synthesized backing init is only type checked once
2020-04-14 10:48:22 -07:00
Owen Voorhees
77aa5642c3 [Diagnostics] Expand test coverage of existing edu notes 2020-04-09 18:18:25 -07:00
Suyash Srijan
724f8c23db [Typechecker] Implement SE-0268 Refine didSet Semantics (#26632) 2020-04-09 01:23:15 +01:00
Holly Borla
008b33ecb3 Merge pull request #30896 from hborla/property-wrapper-invalid-redeclaration
[Property Wrappers] Improve error recovery in buildStorageReference.
2020-04-08 14:50:25 -07:00
Holly Borla
32c338f465 [Property Wrappers] Improve error recovery in buildStorageReference.
Bail out if the backing storage has an error type. This can happen
if there's an invalid redeclaration of the property wrapper, for
example.
2020-04-08 12:45:32 -07:00
Holly Borla
bbfcb55e9e [Property Wrappers] Inject the opaque value placeholder for a property
wrapper original wrapped value expression inside of CSApply.

This prevents type checking the synthesized backing storage initializer
twice - once with the original expression and again with the placeholder.
2020-04-05 19:02:37 -07:00
Slava Pestov
2c2d087242 Sema: More accurate VarDeclUsageChecker analysis with local functions
We used to take all the captures of a local function and treat them all
as read and write usages of vars from an outer scope. Instead, let's
refactor the analysis to walk into local functions.
2020-04-03 18:07:08 -04:00
Slava Pestov
93f0faf109 Sema: Fix false-positive var => let warning in VarUsageDeclChecker
Fixes <rdar://problem/60563962>.
2020-04-03 17:27:43 -04:00
Doug Gregor
5ac8d769fd [Property wrappers] Allow default initialization to infer a type.
Property wrappers are allowed to infer the type of a variable, but this
only worked when the property wrapper was provided with an explicit
initialization, e.g.,

    @WrapsAnInt() var x   // infers type Int from WrapsAnInt.wrappedValue

However, when default initialization is supported by the property wrapper,
dropping the parentheses would produce an error about the missing type
annotation

    @WrapsAnInt var x

Make this second case behave like the first, so that default initialization
works consistently with the explicitly-specified version.
Fixes rdar://problem/59471019.
2020-03-26 13:44:08 -07:00
Doug Gregor
a15a905425 [Property wrappers] Expand testing for backing initializer linkage change. 2020-03-23 15:59:29 -07:00
Hassan El Desouky
d0b6d9f2c1 Improve diagnostic for read-only properties
Make the message within 80 columns width
Improve diagnostic for read-only properties
Improve diagnostic for read-only properties
Improve diagnostic for read-only properties
2020-03-09 04:48:54 +02:00
Owen Voorhees
f0eb312594 Merge pull request #30116 from owenv/property-wrapper-note
[Diagnostics] Tweak @propertyWrapper diagnostic wording and add an educational note
2020-02-29 09:39:18 -08:00
Suyash Srijan
956e918476 [CSSimplify] Move property wrapper fix check after check for conversion restrictions (#30129) 2020-02-28 23:16:32 +00:00
Owen Voorhees
c75a363e1c Tweak @propertyWrapper diagnostics and add an educational note 2020-02-27 20:28:28 -08:00
Robert Widmann
92b8d637f1 [Sema] Always install property wrappers during qualified lookup
Revert the property wrappers part of dd51251014.

Every part of the qualified lookup stack needs to synthesize property
wrapper members, otherwise we'll be subject to the relativistic effects
of semantic lookups in different files. Besides, Codable was the main
source of cycles and circularity under the old scheme.

Resolves rdar://59531889
2020-02-19 14:23:07 -08:00
Matt Diephouse
a3486409c4 Use single quotes instead of backticks in diagnostics 2020-02-17 20:04:33 -05:00
Suyash Srijan
29268e2a34 [PropertyWrappers] Fix a bug with class property wrapper access control (#29023)
* [PropertyWrappers] Class property wrapper cannot have an open init, so make sure to consider that when looking for suitable wrapper inits

* [PropertyWrappers] Extract the access control check into a separate static method
2020-01-14 07:53:48 +00:00
Doug Gregor
64b691fb30 Merge pull request #29005 from DougGregor/functional-pattern-checking
[Type checker] Make typeCheckPattern() a functional request
2020-01-03 21:14:31 -08:00
Doug Gregor
61ac2534e7 [Type checker] Make coercePatternToType return the new Pattern.
Rather than mutating the parameter pattern in place and separately
return whether an error occurred, return the new pattern or NULL if an
error occurred. While here, switch over to ContextualPattern for the
input.

And get rid of that infernal "goto".
2020-01-03 17:27:55 -08:00
Slava Pestov
5a582a6dd5 Merge pull request #28988 from slavapestov/enclosing-self-type-check-expression-crash
Sema: Fix crash-on-invalid with 'enclosing self' property wrappers
2020-01-03 17:34:28 -05:00
Slava Pestov
41a00e5780 Sema: Fix crash-on-invalid with 'enclosing self' property wrappers
The diagnostic is still terrible, but at least we shouldn't crash.

Fixes one manifestation of <rdar://problem/57726880>.

I also filed <https://bugs.swift.org/browse/SR-11989> to track improving
the diagnostic.
2020-01-03 15:06:42 -05:00
Doug Gregor
2a13b1dff0 [Type checker] Stop coercing patterns while type-checking them.
Detangle the "type check" and "coerce" phases somewhat for pattern type
checking, as a precursor to making the former more functional.
2020-01-02 16:15:42 -08:00
swift-ci
2acd425104 Merge pull request #28857 from DougGregor/property-wrappers-unavailable-wrappedvalue 2019-12-18 15:02:26 -08:00
Doug Gregor
b7532f9190 [Property wrappers] Diagnose unavailable wrappedValue
Fixes rdar://problem/53678041 and rdar://problem/57676337; the former was
because we diagnosed unavailable wrappedValue at the null source location
originall, then started suppressing that diagnostic altogether. Produce a
proper diagnostic now.
2019-12-18 13:21:07 -08:00
Holly Borla
94e9fd1d67 [Diagnostics] Use a generic "tuple type not convertible" error message
when there is no contextual type.
2019-12-09 11:25:32 -08:00
Holly Borla
f9a1ab28f4 [ConstraintSystem] Port tuple type mismatches to the new framework 2019-12-06 13:12:57 -08:00
Hamish Knight
40750c01fd [CS] Use different locators for nested 'wrappedValue' lookups
With the new way of caching overloads in the
constraint system, we no longer allow different
overloads to be resolved for the same locator in
the same scope.

Adjust the property wrapper logic
so that it appends Member locator elements for
nested lookups.
2019-12-05 14:47:52 -08:00
Slava Pestov
1df3d1a33c Frontend: Don't interleave parsing and typechecking for the main file
SIL files still require this behavior; if we cleaned that up we
could simplify a fair bit of code here.

Fixes <https://bugs.swift.org/browse/SR-284>,
<https://bugs.swift.org/browse/SR-4426>.
2019-12-05 08:45:55 -05:00
Rintaro Ishizaki
ad4b9df3c0 [CodeCompletion] Suggest the property name in its didSet clause
Previously, property names are hidden in the whole range of the
declarations. Now, it's only hidden in its own initializer range.

rdar://problem/49697202
2019-12-03 18:12:47 -08:00
Doug Gregor
9eac6fe364 [AST] Properties can be explicitly initialized via their wrapper.
The computation for "is explicitly initialized" on a pattern binding
entry didn't account for explicit initialization via the property
wrapper (e.g. @Wrapper(closure: { ... })), which lead to a crash for
properties with optional type. Fixes rdar://problem/57411331.
2019-12-02 18:03:26 -08:00
Suyash Srijan
0cd59069d3 [Test] Update a few failing tests 2019-11-16 16:32:39 +00:00
Slava Pestov
54155fe290 Sema: Check generic requirements of parent context when realizing non-generic types
When realizing a type like Foo<A>.Bar, we have to account for the
possibility that Bar is defined in a constrained extension of Foo,
and has generic requirements beyond those that Foo itself places
on 'A'.

Previously we only handled this for types referenced from the
constraint system as part of openUnboundGenericType(), so we were
allowing invalid types through in type context.

Add the right checking to applyGenericArguments() to close the
hole. Note that the old code path still exists in the constraint
solver; it is used for member accesses on metatype bases only.

Fixes <https://bugs.swift.org/browse/SR-10466>.
2019-11-14 18:26:43 -05:00
Pavel Yaskevich
a7bc52fd9a Merge pull request #28197 from xedin/handle-single-pd-arg-mismatch
[Diagnostics] Produce a tailored diagnostic for property wrapper argu…
2019-11-11 15:13:56 -08:00
Pavel Yaskevich
08f8f4191d [Diagnostics] Produce a tailored diagnostic for property wrapper argument mismatch
Diagnose an attempt to initialize a property, which has a property
wrapper, with a value of an incorrect type.
2019-11-11 12:59:28 -08:00
Jesse Rusak
f5f214de21 Improve warning for inferring an undesirable type (#27797)
* [Sema][Diagnostics] Add fixit for warning when inferring an undesirable type

* [Sema][Diagnostics] Generalize undesirable type warning to include arrays of empty tuples

https://bugs.swift.org/browse/SR-11511
2019-11-10 01:56:58 +00:00
Pavel Yaskevich
cb3a0fbcc8 [ConstraintSystem] Extend use of the treat r-value as l-value fix to more cases
Cover not only immutability but also type mismatch cases and clarify
behavior when one of the sides of the type conversion is optional.
2019-11-05 12:38:13 -08:00
Holly Borla
cc65d2112d [ConstraintSystem] Fix a few places where we should consider
`matchTypes` a success without applying new constraint fixes
due to the presence of holes.
2019-11-05 09:16:57 -08:00
Suyash Srijan
82d154b638 [Test] Update a few existing tests 2019-11-04 22:29:13 +00:00
Robert Widmann
0267384e11 Fixup SourceKit and Tests
Patch up all the places that are making a syntactic judgement about the
isInvalid() bit in a ValueDecl.  They may continue to use that query,
but most guard themselves on whether the interface type has been set.
2019-10-30 15:09:14 -07:00
Holly Borla
e5c99cace6 Merge pull request #27769 from hborla/anyobject-conformance-failure
[ConstraintSystem] Diagnose missing AnyObject conformance using the MissingConformance constraint fix.
2019-10-18 22:10:21 -04:00
Holly Borla
0d95a84e91 [Diagnostics] Improve the error message for when a type fails to satisfy
`AnyObject` layout requirement.
2019-10-18 11:27:21 -07:00
Pavel Yaskevich
8d05192204 Merge pull request #27728 from xedin/port-extraneous-args
[Diagnostics] Diagnose extraneous argument(s) via fixes
2019-10-18 10:42:56 -07:00
Robert Widmann
a52fe65d96 Move a cycle 2019-10-17 16:01:56 -07:00
Robert Widmann
8c73b7db58 Define NamingPatternRequest
Use it to provide an idealized API for the VarDecl case in validateDecl.

In reality, a lot of work is needed to rationalize the dependency
structure of this request.  To start, the callers of
typeCheckPatternBinding must be eliminated piecemeal.  Once that is
done, the AST should introduce pattern binding decls along all the
places where getParentStmt() used to apply.
2019-10-17 09:40:45 -07:00
Robert Widmann
71a525512d Define PatternBindingEntryRequest
Define a request that can be used to grab the fully validated and
type-checked form of a given pattern binding entry.  Using this,
validation of pattern bindings is fully disconnected from validation of
bound variables, and cycles are now picked up by the request evaluator.

Using this, we can go clean up all the callers that are checking a bit
and calling back into typeCheckPatternBinding.  It will also serve as
the basis for a request for the naming pattern for a VarDecl which will
clean that part of validateDecl.
2019-10-17 09:40:45 -07:00
Holly Borla
ef0ecc41e5 [ConstraintSystem] Diagnose missing AnyObject conformance using
the MissingConformance constraint fix.
2019-10-16 20:38:00 -07:00
Pavel Yaskevich
09a36ddf17 [ConstraintSystem] Adjust keypath subscript assert to account for dynamic member lookup
It's possible to find a suitable overload choice for
key path application through keypath dynamic member
lookup and assertion inside `addKeyPathApplicationRootConstraint`
should account for that.

Resolves: rdar://problem/56350060
2019-10-16 16:38:16 -07:00
Pavel Yaskevich
1ffe97f2f8 [Diagnostics] NFC: Adjust more tests improved by extraneous argument(s) fix 2019-10-16 10:19:26 -07:00
Pavel Yaskevich
e09e8c3d72 [Diagnostics] NFC: Adjust diagnostics improved by extraneous arguments fix 2019-10-16 10:19:26 -07:00
Doug Gregor
190d96535c [Property wrappers] Fix source compatibility issue with attribute lookup.
Swift 5.1's lookup for custom attributes skipped associated type
members, which allowed code like the given example to compile. To
maintain source compatibility, identify the narrow case that happens
in practice---the property wrapper is at module scope but is now
shadowed by an associated type---warn about it, and accept it.

Fixes rdar://problem/56213175.
2019-10-11 22:44:50 -07:00