Commit Graph

1183 Commits

Author SHA1 Message Date
Sam Lazarus
501cd91d10 Sema: Add additional assertion before providing keypath application diagnostic 2019-05-06 11:57:11 -04:00
Pavel Yaskevich
43526d031c Merge pull request #24431 from xedin/diag-noescape-param-assignment
[ConstraintSystem] Improve @escaping parameter diagnostics
2019-05-04 20:09:31 -07:00
Sam Lazarus
ed3eaef179 Sema / Test: Revert the error for assignment through read-only key path
This updates the error message so that in the case where we can find a
Decl, it gives the error "cannot assign through subscript: 'name' is a
read-only key path", and in the case where there's no associated Decl, gives the
error message "cannot assign through subscript: key path is read-only".

Additionally updates tests with the new error messages and formats all changes.
2019-05-04 14:03:06 -04:00
Sam Lazarus
6a7c378cbf Sema: Move getting key-path argument logic to a closure 2019-05-03 22:16:56 -04:00
Sam Lazarus
2f94a2132e Sema: Change cast to use dyn_cast instead of dyn_cast_or_null 2019-05-03 22:16:56 -04:00
Sam Lazarus
1a1e77077a Test / Sema: Change the wording of assignment through read-only key path error 2019-05-03 22:16:56 -04:00
Sam Lazarus
1d22e987c8 Sema: Add a diagnostic for assigning using a subscript with a read-only keypath 2019-05-03 22:16:56 -04:00
Pavel Yaskevich
83d6f027f5 [AST] NFC: Add ValueDecl::getOpaqueResultTypeRepr accessor
Follow-up cleanup to simplify code related to diagnosing of
opaque return type conformance mismatches.
2019-05-03 16:49:36 -07:00
Pavel Yaskevich
d275c8afbb [ConstraintSystem] Add a tailored diagnostic for conversion of non-escaping parameter to dependent member type 2019-05-02 21:21:58 -07:00
Pavel Yaskevich
21216d8ecd [ConstraintSystem] Detect and fix invalid refs in dynamic key path member lookup
KeyPath dynamic member lookup is limited to what key path itself
could do, so let's detect and diagnose invalid references just
like we do for regular key path expressions.

Resolves: rdar://problem/50376224
2019-05-02 15:02:11 -07:00
Pavel Yaskevich
62b2da803c [ConstraintSystem] Improve @escaping parameter diagnostics
Detect difference in escapiness while matching function types
in the solver and record a fix that suggests to add @escaping
attribute where appropriate.

Also emit a tailored diagnostic when non-escaping parameter
type is used as a type of a generic parameter.
2019-05-02 00:40:30 -07:00
Pavel Yaskevich
b82a8c544d [ConstraintSystem] Diagnose missing explicit calls in assignment
If the source of the assignment is a function type which has
a result that could be converted to expected destination type,
let's diagnose that as missing call if such function doesn't
have any parameters.
2019-05-01 01:40:11 -07:00
Pavel Yaskevich
1f1e8d99d7 [Diagnostics] Improve missing conformance diagnostics for opaque return
New diagnostic framework can already identify contextual failures
related to opaque return types, `RequirementFailure` just needs
to get adjusted to identify correct affected declaration and provide
tailored diagnostic.

Resolves: rdar://problem/49582531
2019-04-29 16:17:45 -07:00
Pavel Yaskevich
94977ee175 [TypeChecker] Improve contextual mismatch diagnostics for key path
Detect situations where key path doesn't have capability required
by the context e.g. read-only vs. writable, or either root or value
types are incorrect e.g.

```swift
struct S { let foo: Int }
let _: WritableKeyPath<S, Int> = \.foo
```

Here context requires a writable key path but `foo` property is
read-only.
2019-04-26 10:59:01 -07:00
Suyash Srijan
20cfa14423 [CSDiagnostics] Removes lazy attributes when applying computed property fix-it 2019-04-25 17:59:07 +01:00
Pavel Yaskevich
6fdb5482d4 [Diagnostics] Diagnose invalid method references in key path 2019-04-22 16:40:14 -07:00
Pavel Yaskevich
d6a3a31ae9 [ConstraintSystem] Detect and fix use of method references in key path
Referencing (instance or static) methods in the key path is not
currently allowed, solver should be responsible for early detection
and diagnosis of both standalone e.g. `\.foo` and chained
e.g. `\.foo.bar` (where foo is a method) references in key path
components.

```swift
struct S {
  func foo() -> Int { return 42 }
}

let _: KeyPath<S, Int> = \.foo
```

Resolves: rdar://problem/49413561
2019-04-22 14:56:15 -07:00
Pavel Yaskevich
23403500bd Merge pull request #24097 from xedin/diag-mutating-getter-in-keypath
[ConstraintSystem] Detect and diagnoses use of members with mutating getters in key path
2019-04-18 13:12:22 -07:00
Pavel Yaskevich
eaf1dc0012 [Diagnostics] Diagnose use of member with mutating getter in key path 2019-04-17 11:51:33 -07:00
Pavel Yaskevich
c33b726486 [Diagnostics] Extract logic common to all key path invalid ref diagnostics 2019-04-17 11:34:13 -07:00
Slava Pestov
eed84abda9 Sema: Add TVO_CanBindToNoEscape
We have a systemic class of issues where noescape types end up bound to
type variables in places that should not. The existing diagnostic for
this is ad-hoc and duplicated in several places but it doesn't actually
address the root cause of the problem.

For now, I've changed all call sites of createTypeVariable() to set the
new flag. I plan on removing enough occurrences of the flag to replicate
the old diagnostics. Then we can continue to refine this over time.
2019-04-16 23:01:33 -04:00
Pavel Yaskevich
55bc16e785 [Diagnostics] Diagnose static member reference as a key path component 2019-04-15 23:42:34 -07:00
Suyash Srijan
072e84acd6 [CSSimplify] Reject key path if root type is AnyObject (#23820)
Detect situations where `AnyObject` is attempted to be used as a root type of the key path
early and diagnose via new diagnostics framework.
2019-04-14 12:18:35 -07:00
Pavel Yaskevich
439335ddb0 [Diagnostics] Extend keypath subscript index missing Hashable to support dynamic member lookup 2019-04-10 15:10:47 -07:00
Pavel Yaskevich
c3460f825d [Diagnostics] Diagnose keypath subscript components with missing Hashable conformances 2019-04-10 13:51:12 -07:00
Pavel Yaskevich
dd810a7b24 [Diagnostics] Improve mutability diagnostics related to dynamic member lookup
Since there is a way to mutate through use of writable keypath
diagnostics have to be adjusted to point to the members found
via keypath member lookup instead to using catch-all
"immutable base" diagnostic.
2019-04-01 12:41:55 -07:00
Pavel Yaskevich
f95d9b092e [TypeChecker] Add new type of overload choice to support keypath dynamic lookup 2019-04-01 12:40:39 -07:00
Pavel Yaskevich
1ee66cd653 Merge pull request #23500 from theblixguy/fix/SR-9267
[CSDiag] Improving the fix-it for defining computed variables
2019-03-25 11:02:45 -07:00
Suyash Srijan
56b0c55dfb [cs] make tryComputedPropertyFixIts() a private instance method 2019-03-25 01:33:41 +00:00
Suyash Srijan
5a8e1fa955 [cs] extract computed property fix-it into separate method 2019-03-25 00:07:41 +00:00
Suyash Srijan
9750762b75 [csdiag] missing function call failure here as a backup 2019-03-23 02:11:13 +00:00
Suyash Srijan
1b62039c76 [cssimplify] add a fix for contextual type conversion for function type 2019-03-22 23:40:43 +00:00
Ben Langmuir
f5a216fc04 Merge pull request #23411 from benlangmuir/cc-1-close
[code-completion] Add type context for single-expression closures
2019-03-20 06:56:49 -07:00
Ben Langmuir
2b5a8a5be7 Fix assertion failure in validation test
Seen in validation-test/IDE/crashers_fixed/019-swift-vardecl-emitlettovarnoteifsimple.swift
2019-03-19 09:35:25 -07:00
Pavel Yaskevich
688042becf [Diagnostics] Add inaccessible member diagnostic 2019-03-18 13:48:08 -07:00
Slava Pestov
9626340d4b Sema: Remove unused -fix-string-to-substring-conversion flag 2019-03-14 22:08:43 -04:00
Pavel Yaskevich
3940cebebf [Diagnostics] Don't suggest unwrap with default value if type is not materializable 2019-03-08 01:07:54 -08:00
Pavel Yaskevich
39dd6306c6 [Diagnostics] Refactor missing optional unwrap diagnostic
Instead of passing all of the information available in the diagnostic
to static functions, let's bring "default value" and "force unwrap"
fix-it logic under "missing optional unwrap diagnostic" umbrella.
2019-03-07 15:39:42 -08:00
Pavel Yaskevich
2e14bec250 [Diagnostics] Add out-of-order argument diagnostic 2019-03-04 20:03:54 -08:00
Pavel Yaskevich
9999a47197 [Diagnostics] Add closure parameter destructuring diagnostic 2019-03-04 11:37:43 -08:00
Pavel Yaskevich
aeaa26d926 [CSDiagnostics] Add missing arguments failure
Currently only supports closures, but could be easily expanded
to other types of situations e.g. function/member calls.
2019-02-26 13:29:35 -08:00
Suyash Srijan
34f8670d2a [CS] Use fixes to diagnose instance member on type (or vice versa) access (#21830)
This PR migrates instance member on type and type member on instance diagnostics handling to use the new diagnostics framework (fixes) and create more reliable and accurate diagnostics in such scenarios.
2019-02-22 16:57:26 -08:00
Pavel Yaskevich
8e5d5ed7cc Merge pull request #22802 from xcadaverx/xcadaverx/SR-9851_Incorrect_fix_it_logical_not_optional_bool
[Sema] SR-9851 - Add parens when needed for nil coalescing fixits
2019-02-22 11:33:09 -08:00
Daniel Williams
1d88c47aaf [Sema] SR-9851 - Add parens when needed for nil coalescing fixits
https://bugs.swift.org/browse/SR-9851
2019-02-21 21:03:29 -08:00
Pavel Yaskevich
d4b67bf3f7 [Diagnostics] Improve argument labeling diagnostics
Extend new labeling diagnostics (via fixes) to support
member references and subscripts.
2019-02-21 16:42:56 -08:00
Pavel Yaskevich
ff2510816d [CSDiagnostics] Use correct overload locator when requirement belongs to explicit init ref
Previously the logic to determine path to the selected overload
in such case was simplistic and only checked the name to be
of constructor, but `ConstructorMember` path is formed only if
member reference is a constructor delegation e.g. `self.init` or
`super.init` in an initializer context.
2019-02-20 12:54:27 -08:00
David Zarzycki
65a452f764 Merge pull request #22689 from davezarzycki/fix_overloaded_generics_crash
[Sema] NFC: fix assert-only crasher with overloaded generics
2019-02-19 08:21:43 -05:00
Pavel Yaskevich
a7c66ca476 [CSDiagnostics] Imporove requirement diagnostics originating in contextual type
Detect that failed requirement comes from contextual type and use
that information to determine affected declaration.

Resolves: rdar://problem/47980354
2019-02-18 17:58:28 -08:00
Pavel Yaskevich
70b5bce791 [CSFix] Use fully qualified locators for requirement failures
Would help to diagnose failures where requirement comes from
contextual type, also simplifies logic around requirement fixes
to some degree.
2019-02-18 12:03:46 -08:00
David Zarzycki
51ef3c014a [Sema] NFC: fix assert-only crasher with overloaded generics 2019-02-18 08:49:42 -05:00