Commit Graph

1208 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
b009bf6154 Merge pull request #22630 from xedin/add-generic-context-to-locator
[ConstraintLocator] Add generic signature to `OpenedGeneric` element
2019-02-15 17:36:19 -08:00
Pavel Yaskevich
4f0f090e36 [CSDiagnostics] Use generic signature to retrieve failing requirement 2019-02-14 12:18:17 -08:00
Parker Schuh
b12fcb50db IntegerLiteralExpr now is lowered directly into SIL.
For context, String, Nil, and Bool already behave this way.

Note: Before it used to construct (call, ... (integer_literal)), and the
call would be made explicit / implicit based on if you did eg: Int(3) or
just 3. This however did not translate to the new world so this PR adds
a IsExplicitConversion bit to NumberLiteralExpr. Some side results of
all this are that some warnings changed a little and some instructions are
emitted in a different order.
2019-02-14 11:54:16 -08:00
Pavel Yaskevich
75b5824bf9 Merge pull request #22480 from xedin/rdar-47871590
[ConstraintSystem] Diagnose conditional requirement failures via fixes
2019-02-11 14:58:08 -08:00
Pavel Yaskevich
42e0f21409 [CSDiagnostics] Improve requirement failure source detection
If affected declaration is a static or instance memeber (excluding
operators) and failed requirement is declared in other nominal type
or extension, diagnose such problems as `in reference` instead of
claiming that requirement belongs to the member itself.
2019-02-08 15:05:42 -08:00
Pavel Yaskevich
dfac0d8323 [CSDiagnostics] Augment RequirementFailure to support conditional requirements 2019-02-08 11:14:41 -08:00
Pavel Yaskevich
1d42e16ad2 [ConstraintSystem] Detect invalid implicit ref to initializer on non-const metatype
Situations like:

```swift
struct S {}
func foo(_ s: S.Type) {
  _ = s()
}
```

Used to be diagnosed in solution application phase, which means that
solver was allowed to formed an incorrect solution.
2019-02-07 00:17:07 -08:00
Pavel Yaskevich
0595cefab3 [CSDiagnostics] Add diagnostics for two kinds of incorrect initializer reference
- Attempting to construct class object using metatype value via
  non-required initializer

- Referencing initializer of protocol metatype base

Both of the diagnostics are used by `AllowInvalidInitRef` fix.
2019-02-05 10:28:41 -08:00
Pavel Yaskevich
462cb1ffb1 Merge pull request #22124 from xedin/diagnose-partial-applies
[CSDiagnostics] Diagnose invalid partial application
2019-01-28 10:44:56 -08:00
Pavel Yaskevich
1c79380a12 [CSFix] Couple of small cleanups related to ForceOptional
* Make sure that base and unwrapped types aren't null
* Don't allocate `ForceOptional` fix if nothing has been unwrapped
  in `simplifyApplicableFnConstraint`
* Add sugar reconstitution support to `FailureDiagnostic::resolveType`
* Format diagnostics a bit better
2019-01-26 00:48:01 -08:00
Pavel Yaskevich
174fd14090 [CSDiagnostics] Diagnose invalid partial application of init delegation 2019-01-25 14:18:04 -08:00
Pavel Yaskevich
315a0adc93 [CSDiagnostics] Add invalid partial apply diagnostic for mutating methods 2019-01-25 14:17:54 -08:00
Suyash Srijan
6a0a1dec05 [cs] use anchor instead of locator, etc 2019-01-25 21:36:07 +00:00
Suyash Srijan
76b8209b25 [cs] store base type and unwrapped type in the fix 2019-01-25 10:13:37 +00:00
Suyash Srijan
f5264b9779 [diag] fix incorrect diagnostic when unwrapping double optional 2019-01-22 22:03:40 +00:00
Slava Pestov
81c5a67489 Merge pull request #21758 from pschuh/s-1
Rename NameAliasType to TypeAliasType.
2019-01-10 15:20:41 -05:00
Pavel Yaskevich
74a8ee177e [Diagnostics] Diagnose missing members via fixes
Try to fix constraint system in a way where member
reference is going to be defined in terms of its use,
which makes it seem like parameters match arguments
exactly. Such helps to produce solutions and diagnose
failures related to missing members precisely.

These changes would be further extended to diagnose use
of unavailable members and other structural member failures.

Resolves: rdar://problem/34583132
Resolves: rdar://problem/36989788
Resolved: rdar://problem/39586166
Resolves: rdar://problem/40537782
Resolves: rdar://problem/46211109
2019-01-09 17:29:49 -08:00
Parker Schuh
f5859ff46e Rename NameAliasType to TypeAliasType. 2019-01-09 16:47:13 -08:00
Pavel Yaskevich
91e97a0c8f [Diagnostics] Diagnose ambiguity resulting from subscript operator fix as a missing member
Since the rule is to prioritize names over types, let's diagnose
ambiguous solutions containing subscript operator fix as missing
member and list possible candidates to use.
2019-01-08 12:09:02 -08:00
Pavel Yaskevich
06a7ad63f8 [Diagnostics] Diagnose subscript operator misuse via fixes
Fix to use subscript operator instead of spelled out name helps
to produce a solution, that makes it much easier to diagnose
problems precisely and provide proper fix-its, it also helps to
diagnose ambiguous cases, and stacks up nicely with other errors.
2019-01-08 12:06:40 -08:00
Pavel Yaskevich
9818b55266 [CSDiagnostics] Add MissingCall failure
It's used to diagnose cases when function/method are used as
a property instead of being called.
2018-12-11 18:44:41 -08:00
Pavel Yaskevich
202234f325 [CSDiagnostics] Diagnose invalid optional unwrap via fixes
Detect and fix situations when (force) unwrap is used on
a non-optional type, this helps to diagnose invalid unwraps
precisely and provide fix-its.

Resolves: [SR-8977](https://bugs.swift.org/browse/SR-8977)
Resolves: rdar://problem/45218255
2018-12-05 08:10:07 -08:00
Pavel Yaskevich
03d283171c [CSDiagnostics] Fix requirement source lookup to support member references
Fuzzing found a problem related to re-typecheck introducing
`MemeberRefExpr` into AST with failing requirements which
are then diagnosted via fixes, quite unlikely case to be
found in the wild.
2018-11-30 13:48:19 -08:00
Pavel Yaskevich
07e5d54855 [CSDiagnostics] Add custom diagnostic for invalid @autoclosure forwarding
Suggest to add `()` (form a call) to correctly forward argument function
originated from `@autoclosure` parameter to function parameter itself
marked as `@autoclosure`.
2018-11-21 12:17:25 -08:00
Mark Lacey
018498fb2f Merge pull request #16942 from bjhomer/bjhomer/optional-try-flattening
Flatten nested optionals resulting from try? and optional sub-expressions
2018-11-16 11:14:05 -08:00