Commit Graph

547 Commits

Author SHA1 Message Date
Matt Diephouse
863d7d36f2 [Diagnostics]: Rewrite "no subscript members" error
• Change name to match names of member diagnostics.

• Explicitly call out that this is a "value of type". This matches the error from non-existent methods and properties.

• Don't call them "subscript members". That term is never used in documentation and "member" doesn't add anything besides confusion.
2018-06-13 13:35:24 -04:00
Pavel Yaskevich
934351a8e3 [Diagnostics] Hint contextual type diagnostics with expression type if known
Avoid a re-typecheck in `diagnoseContextualConversionError` if the
expression type is already known and only return `true` if we know
that at least one error diagnostic has been emitted otherwise there
is a risk that type-check is going to return without any and fail
in verifier.

Resolves: rdar://problem/40002266
2018-05-12 13:56:53 -07:00
Michael Ilseman
dfa281dd54 [test] Update diagnostic test for SR-7599 2018-05-03 17:32:58 -07:00
Anthony Latsis
4099e85da6 [Diagnostics & Tests] SR-6052 Prevent nil capitalization (#16256)
And provide better semantic background by surrounding 'nil' in ticks when it is referred to as a value

Added missing tests for certain cases involving nil capitalization
2018-05-03 09:10:30 -07:00
fischertony
2d375078a3 tests updated for expression_unused_result_unknown diagnostic new text 2018-04-21 02:46:19 +03:00
Joe Groff
62771a0c9d stdlib: Add withUnsafeBytes(of:) and withUnsafePointer(to:) for immutable arguments.
Since the functions produce pointers with tightly-scoped lifetimes there's no formal reason these have to only work on `inout` things.  Now that arguments can be +0, we can even do this without copying values that we already have at +0.
2018-04-18 09:13:45 -07:00
David Zarzycki
67710606e6 [Parse] Move tok::amp_prefix closer to parameter list logic
The amp_prefix token is currently tolerated in any unary expression
context and then diagnosed later by Sema. This patch changes parsing to
only accept tok::amp_prefix in its allowed position: parameter lists.

This also fixes two "compiler crasher" tests.
2018-03-30 17:56:36 -04:00
Pavel Yaskevich
5208049ff8 [CSBindings] Form bindings correctly when they come from 'OptionalObject' constraint
Fixes a bug in `getPotentialBindings` when the source of the bindings
is 'OptionalObject' constraint and type variable is on the left-hand
side of that constraint, that makes such type variable always have an
optional type since right-hand side of 'OptionalObject' is its 'object'
type.

Resolves: rdar://problem/37508855
2018-02-13 14:25:00 -08:00
Ben Cohen
9ee856f386 [stdlib][WIP] Eliminate (Closed)CountableRange using conditional conformance (#13342)
* Make Range conditionally a Collection

* Convert ClosedRange to conditionally a collection

* De-gyb Range/ClosedRange, refactoring some methods.

* Remove use of Countable{Closed}Range from stdlib

* Remove Countable use from Foundation

* Fix test errors and warnings resulting from Range/CountableRange collapse

* fix prespecialize test for new mangling

* Update CoreAudio use of CountableRange

* Update SwiftSyntax use of CountableRange

* Restore ClosedRange.Index: Hashable conformance

* Move fixed typechecker slowness test for array-of-ranges from slow to fast, yay

* Apply Doug's patch to loosen test to just check for error
2018-02-01 20:59:28 -08:00
Doug Gregor
4672c11607 Fix up some test cases whose diagnostics changed for the better. 2018-01-25 17:21:35 -08:00
Max Moiseev
6ac167dad4 Merge pull request #13707 from moiseev/strideable-pointer-perf
🛑[stdlib] Attempt to dispatch pointer + via Strideable conformance
2018-01-17 14:46:47 -08:00
Pavel Yaskevich
ce847cc74b Merge pull request #13272 from chuganzy/SR-6272
[DiagnosticsQoI] SR-6272 Tailored diagnostics with fixits for numerical conversions
2018-01-12 01:06:18 -08:00
Max Moiseev
54f79a40d7 Fix tests 2018-01-08 15:46:28 -08:00
Takeru Chuganji
0df987a4ff SR-6272 Add fix-it if there is only one candidate 2018-01-03 13:26:36 -08:00
Takeru Chuganji
c80b569c2f SR-6272 Use calleeInfo instead 2017-12-17 22:06:20 +09:00
Takeru Chuganji
72cf1585a0 SR-6272: Use contextual type if available 2017-12-16 15:58:57 +09:00
Takeru Chuganji
5a56d4d706 SR-6272: Add more tests 2017-12-16 15:12:46 +09:00
Takeru Chuganji
06b9f78106 Revert "SR-6272: Add tests"
This reverts commit b2059c62d3.
2017-12-16 14:39:00 +09:00
Ben Cohen
4ddac3fbbd [stdlib] Eradicate IndexDistance associated type (#12641)
* Eradicate IndexDistance associated type, replacing with Int everywhere

* Consistently use Int for ExistentialCollection’s IndexDistance type.

* Fix test for IndexDistance removal

* Remove a handful of no-longer-needed explicit types

* Add compatibility shims for non-Int index distances

* Test compatibility shim

* Move IndexDistance typealias into the Collection protocol
2017-12-08 12:00:23 -08:00
Takeru Chuganji
b2059c62d3 SR-6272: Add tests 2017-12-05 22:32:52 -08:00
Ben Cohen
dcab9493ae Removed some warnings (#12753) 2017-11-30 15:12:56 -08:00
gregomni
cdce937c51 Beginning changes to provide more info out about unresolved params, but even
changing is<UnresolvedType> to hasUnresolvedType turns out is enough to fix a
radar.
2017-10-21 19:33:36 -07:00
Pavel Yaskevich
7d2e29a349 [AST] Fix canonicalization of the function input types
Currently canonicalization of the input type was happening standalone
which means that outer parens are regarded as suger and removed,
this is incorrect after SE-0110 and such parens can't be stripped.
2017-10-05 16:11:56 -07:00
Slava Pestov
8ff8b7e8a1 Add another test case for <https://bugs.swift.org/browse/SR-5932> 2017-09-29 16:58:19 -07:00
Slava Pestov
044af751f3 Sema: Fix a failure to emit a diagnostic
CSDiag was misinterpreting the result of checkGenericArguments().

A result of SubstitutionFailure does not mean a diagnostic was
emitted, only a result of Failure means that. This fixes a case
where we did not emit a diagnostic, result in a crash on invalid.

The diagnostic is still poor, but that's better than crashing.

Fixes <https://bugs.swift.org/browse/SR-5932>,
<rdar://problem/34522739>.
2017-09-27 16:39:06 -07:00
Max Moiseev
4c0368a02a [test] Cleaning up tests 2017-08-29 10:04:39 -07:00
Pavel Yaskevich
80408d6b82 [QoI] Prevent a crash during diagnostics of ternary/if statements
While trying to diagnose problems with ternary/if statements don't
allow clauses, when type-checked separately, to have unresolved type
variables because that doesn't help to find errors.
2017-08-03 12:16:53 -07:00
Pavel Yaskevich
e8744af283 [QoI] Improve diagnostics for assignment expression
Currently `visitAssignExpr` always attempts to use type
derived from destination as a contextual type for assignment
source type-checking, which doesn't always lead to better
results.

Resolves: SR-5081
2017-08-02 18:17:49 -07:00
Joe Groff
605804cd17 Sema: Don't allow key path literals to refer to static members.
This is theoretically supportable some day, but isn't implemented today. Fixes rdar://problem/33318422 | SR-5453.
2017-07-19 15:27:43 -07:00
Dave Abrahams
9159239995 Un-revert "[stdlib] String index interchange, etc." (#10812)
I failed to merge the upstream changes to swift-corelibs-foundation at the same
time as I merged that #9806, and it broke on linux. Going to get it right this
time.
2017-07-07 12:13:25 -07:00
Xi Ge
d9fb110674 Revert "[stdlib] String index interchange, etc." (#10812)
rdar://33186295
2017-07-07 12:03:16 -07:00
Dave Abrahams
e523c80339 [stdlib] Index interchange, part I 2017-07-07 00:59:04 -07:00
Alex Hoppen
ff6747de77 Merge pull request #10745 from ahoppen/diagnostics-adjustments-declname
[Diag] Change function diagnostics to take a DeclName parameter
2017-07-06 13:26:56 +02:00
David Rönnqvist
00833a2343 [QoI] Improve the fix-it for out-of-order arguments.
Change the fix-it to move the argument to its correct location in one go. This happens by removing it from one location and inserting it in the other (as opposed to the original implementation which swapped one argument with the preceding one). The commas separating the arguments are adjusted to match the moved argument.

Add new tests for reordering regular arguments, variadic arguments, and function arguments.

Resolves: SR-4715 rdar://problem/31849281
2017-07-02 10:15:18 +02:00
Alex Hoppen
f35f29d9cf [Diag] Change function diagnostics to take a DeclName parameter
This provides richer error messages that include the function's
parameters
2017-07-01 13:37:08 +02:00
Pavel Yaskevich
1ffac2e651 [QoI] Improve diagnostics related to member calls
When trying to diagnose problems related to calls where
function is represented by a member of nominal type let's
attempt to be more cautious while type-checking function
expression without it's arguments, because it could produce
unrelated diagnostics.

Resolves: rdar://problem/32551313, rdar://problem/28456467, rdar://problem/31671195
2017-06-27 15:49:11 -07:00
Pavel Yaskevich
4e6677e7c4 [QoI] Improve contextual error diagnostics related to calls
Currently some contextual errors are discovered too late
which leads to diagnostics of unrelated problems like argument
mismatches, these changes attempt to improve the situation
and try to diagnose contextual errors related to calls
before everything else.

Resolves: SR-5045, rdar://problem/32934129
2017-06-26 13:12:32 -07:00
Pavel Yaskevich
6231f85be9 [ConstraintSolver] Use a flag to prevent solver from removing possible solutions
In some situations e.g. while trying to shrink domains of the type
variables before attempting search, use a flag to tell constraint
system to retain all of the viable solutions otherwise solver could
loose some of the information required to produce complete solution.

Resolves: rdar://problem/32726044
2017-06-22 00:11:32 -07:00
Pavel Yaskevich
6180ecef73 [QoI] Don't suggest var to let when binding inside for-statement
Instead of doing that, suggest removing 'var' altogether because
'let' cannot be used directly in an implicitly immutable context.

Resolves: rdar://problem/32390726
2017-06-09 01:10:40 -07:00
Pavel Yaskevich
573f20e55c [QoI] Unify member diagnostics into one FailureDiagnosis method 2017-05-17 12:00:23 -07:00
Pavel Yaskevich
9a07f28ac4 Merge pull request #9587 from xedin/rdar-31973368
[QoI] Extend single tuple parameter diagnostics to function/subscript calls
2017-05-15 21:29:42 -07:00
Pavel Yaskevich
ead1447aa1 [QoI] Extend single tuple parameter diagnostics to function/subscript calls
Properly diagnose cases of function/subscript argument tuple
structuring/destructuring related by not limited to SE-0110.

Resolves: rdar://problem/31973368
2017-05-15 18:41:41 -07:00
Pavel Yaskevich
8e8ead31d3 [QoI] Improve diagnostics for Smart KeyPath
Add `FailureDiagnostics::visitKeyPathExpr` to try and diagnose contextual
value type problems related to Smart KeyPath feature. If problems with
contextual value type can't be diagnosed let's walk components and see
if there are any structural problems with expression itself e.g. unknown
members and incorrect types in the path.

Resolves: rdar://problem/32101765
2017-05-15 14:43:37 -07:00
David Farler
0c48f71384 Migrator/QoI: Function input type: Don't fix Void to (Void), but fix (Void) to ()
```swift
func foo(f: Void) -> ()) {}
```

This compiler currently suggests we change this to:

```swift
func foo(f: (Void) -> ()) {}
```

That's `(()) -> ()`, almost certainly not what someone wants in Swift
4. We should suggest changing that to:
```swift
func foo(f: () -> ()) {}
```

Additionally,

```swift
func foo(f: (Void) -> ()) {}
```

Should trigger a warning that the `(Void)` input type is `(())`, and you
can't supply `()` to it in Swift 4, and suggest a fix-it change it to:

```swift
func foo(f: () -> ()) {}
```

rdar://problem/32143617
2017-05-13 17:36:28 -07:00
Pavel Yaskevich
c0bc4f20be [QoI] Improve diagnostics for unresolved member with incorrect arguments
`FailureDiagnosis::visitUnresolvedMemberExpr` tries to use the same logic
as `diagnoseSingleCandidateFailures` so instead of doing that let's remove
some of the special handling and use `diagnoseSingleCandidateFailures`
directly instead, which improves label diagnostics and handles more erroneous
cases as well.

Resolves: rdar://problem/31898542
2017-05-11 01:31:33 -07:00
Pavel Yaskevich
5adeff065c [QoI] Improve diagnostics for calling instance methods on type or in static context.
Previously situations like `self.foo(...)` wouldn't be considered as viable
for diagnosing the instance method on type calls, because the base wasn't
TypeExpr, which only accounts for e.g. `X.foo`, instead of validating base
expression itself this patch checks if the _type_ of base expression is
Metatype which is less restrictive.

Resolves: SR-4692.
2017-05-07 01:29:50 -07:00
Slava Pestov
dd7b62c0d8 Sema: Fix crash with ambiguous overload inside a trailing closure
Any ambiguity inside of a call with a trailing closure
call was going down the code path that would tell you to
add an argument label... but the ambiguity might not be
with the call that has the trailing closure itself, and
instead something inside.
2017-05-05 23:54:22 -07:00
Joe Groff
cf6cc484c0 Switch on key paths.
Enabling the global subscript degrades some diagnostics (rdar://problem/31724211).
2017-05-05 08:32:41 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Ben Cohen
38903764df Revert "Revert "[stdlib] One-sided ranges and RangeExpression (#8710)"" 2017-04-30 16:47:23 -07:00