Commit Graph

664 Commits

Author SHA1 Message Date
Jordan Rose
8d9535203b Give a proper error when a member type is inaccessible. (#4033)
This doesn't yet cover top-level types or top-level non-type values,
but it's a start.

Part of rdar://problem/27663403.
2016-08-05 12:41:45 -07:00
Xi Ge
0c8ace9413 [FixCode] Using coercion (as) instead of forced-coercion (as!) when the former is applicable. rdar://27683732 (#4008)
This fixit is migration-critical to help users call functions now take 'Any' or 'NSHashble' while used to take 'AnyObject'. We insert coercion to the original call sites.
2016-08-04 13:28:42 -07:00
Xi Ge
03d8017482 Addressing Chris' code review comments on 6324314. NFC (#3982) 2016-08-04 10:43:08 -07:00
Xi Ge
63243147af [FixCode] Help users construct mutable pointer from a pointer by inserting 'mutating'. rdar://27500578 (#3971) 2016-08-03 16:30:06 -07:00
Ted Kremenek
6f743dba7c Merge pull request #3939 from milseman/noescape_by_default
[noescape-by-default] Better diagnostics for parameters
2016-08-02 21:59:44 -07:00
Michael Ilseman
49394eb370 [noescape-by-default] incorporate Doug's feedback
Added sugared test case
2016-08-02 21:06:40 -07:00
Michael Ilseman
4ca39fd284 [noescape-by-default] Expand useful diagnostics to more cases
Extends the more useful diagnostics for non-escaping function
parameters used in @escaping contexts to apply to all functions that
are equivalent modulo ExtInfo.
2016-08-02 14:52:43 -07:00
Doug Gregor
31edf710bf [Sema] Improve diagnostics for attempt to throw an error *code*
Attempting to throw an error code value, e.g.,

  throw CocoaError.fileNoSuchFileError

is now ill-formed, although it was well-formed prior to the
introduction of NSError bridging (SE-0112). Provide a specialized
diagnostic with a Fix-It to add the appropriate parentheses:

  throw CocoaError(.fileNoSuchFileError)

Fixes rdar://problem/27543121.
2016-08-02 14:47:18 -07:00
Michael Ilseman
ce1565a110 [noescape-by-default] Better diagnostics for parameters
Issue better diagnostics, along with notes and fixits, for the common
case of using an implicitly non-escaping parameter of function type in
a context expecting an @escaping closure. Provides even more specific
diagnostics for common scenarios such as passing to another function
or assignment.
2016-08-02 14:20:11 -07:00
Jordan Rose
f42158b12e Revert "[Sema] ban multi-arguments to tuple coercion" (#3922)
It breaks cases where there really is a single unlabeled argument of tuple type, like this:

  let pairs = [(1, "A"), (2, "B")]
  print(pairs.map { $0.0 })
2016-08-01 19:22:19 -07:00
Doug Gregor
f1706303a0 Merge pull request #3895 from dduan/se0110_a-pr
[Sema] ban multi-arguments to tuple coercion
2016-07-31 23:00:32 -07:00
Chris Lattner
3f827c0ca1 When diagnosing a missing parameter, point to the decl that is being called.
This resolves:
<rdar://problem/24106465> QoI: missing argument to memberwise initializer doesn't tell me its signature
2016-07-31 16:34:52 -07:00
Daniel Duan
c9b73dacc2 [Sema] ban multi-arguments to tuple coercion
Implements part of SE-0110. Single argument in closures will not be accepted if
there exists explicit type with a number of arguments that's not 1.

```swift
let f: (Int, Int) -> Void = { x in } // this is now an error
```

Note there's a second part of SE-0110 which could be considered additive,
which says one must add an extra pair of parens to specify a single arugment
type that is a tuple:

```swift
let g ((Int, Int)) -> Void = { y in } // y should have type (Int, Int)
```

This patch does not implement that part.
2016-07-31 16:22:57 -07:00
Chris Lattner
fb7a4e9ded Generalize the closure work from yesterday, enough to fix:
rdar://17687826 - QoI: error message when reducing to an untyped dictionary isn't helpful
2016-07-31 15:25:17 -07:00
Chris Lattner
f1ea135f8c fix <rdar://problem/27384685> QoI: Poor diagnostic when assigning a value to a method
We previously said:
  x.method = 1 // error: cannot assign to property: 'x' is immutable

we now say:
error: cannot assign to property: 'method' is a method
2016-07-31 15:03:38 -07:00
Chris Lattner
807345a909 When we get an abiguity problem with a multi-statement closure return type, it is
almost always the case that the user didn't know what the rules are between
single expression and multistatement closures, and they often don't know how to
fix the problem.

Address this by doing some heroics when we detect this situation.  We now go dive
into the closure body, type check the explicit returns within it, and can usually
divine the right answer.  When we do that, generate a fixit hint that generates a
modification to the existing signature, or synthesizes the entire signature from
scratch.  This addresses:
<rdar://problem/22123191> QoI: multi-line closure with failure to infer result type should add a fixit
2016-07-30 14:36:47 -07:00
Chris Lattner
4e3ec30f89 refactor some static functions to be methods on FailureDiagnosis, NFC. 2016-07-30 14:36:47 -07:00
Chris Lattner
84d27f8528 fix <rdar://problem/21675896> QoI: [Closure return type inference] Swift cannot find members for the result of inlined lambdas with branches
We previously produced the unhelpful error message:

x.swift:11:7: error: type of expression is ambiguous without more context

we now produce:

error: unable to infer closure return type in current context

which is going in the right direction.
2016-07-29 21:22:01 -07:00
Robert Widmann
b79fa44da5 Merge pull request #3878 from CodaFi/decltype
[SE-0096] Implement type(of:)
2016-07-29 18:05:01 -07:00
Chris Lattner
764d0fc371 improve the diagnostics for when a multi-statement closure has no inferred result type.
Previously:

error: generic parameter 'T' could not be inferred
now:
error: unable to infer closure return type in current context

There is still more to do, but this fixes:
<rdar://problem/23570873> QoI: Poor error calling map without being able to infer "U" (closure result inference)
2016-07-29 17:49:23 -07:00
Robert Widmann
14dc86cf15 Polish off uses of dynamicType in codebase 2016-07-29 16:58:40 -07:00
Chris Lattner
773d521bfa fix rdar://25271859 QoI: Misleading error message when expression result can't be inferred from closure
We previously produced the error message:

rdar25271859.swift:14:11: error: value of tuple type '(Float, Int)' has no member '0'
  a.map { $0.0 }
          ^~ ~

We now produce:

rdar25271859.swift:15:5: error: generic parameter 'U' could not be inferred
   .andThen { dataResult in
    ^

which is at least is correct, if not yet helpful.
2016-07-29 16:45:17 -07:00
Michael Gottesman
992f576d55 Merge pull request #3830 from rudkx/fix-25563498
Fix crash during type checker diagnostic emission.
2016-07-28 23:02:05 -07:00
Doug Gregor
202cf2e754 [SE-0111] Track function reference kinds in member references.
Extend the handling of function reference kinds to member references
(e.g., x.f), and therefore the logic for stripping argument labels. We
appear to be stripping argument labels from all of the places where it
is required.
2016-07-28 15:41:59 -07:00
Doug Gregor
8c7e75afa0 [AST] Eliminate OverloadedMemberRefExpr.
This expression kind was introduced in exactly one place, and only
with one member. That place can use MemberRefExpr instead.
2016-07-28 14:44:23 -07:00
Mark Lacey
8ed813080e Fix crash during type checker diagnostic emission.
We were crashing attempting to diagnose the case where we cannot assign
an array literal to a type conforming to _ArrayProtocol because we don't
know the element types of the conforming type.

We still don't give a great diagnostic for this, so I've
opened (rdar://problem/27594154) to track improving it.

Resolves rdar://problem/25563498.
2016-07-28 12:00:34 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Doug Gregor
79c00ead96 [CSDiag] We have trailing closure info for subscripts now. Use it. 2016-07-26 11:23:57 -07:00
swift-ci
7974977828 Merge pull request #3659 from rintaro/args-order-diag 2016-07-26 09:30:10 -07:00
Doug Gregor
33d8b469d4 [SE-0111] Store argument labels directly on subscript expressions.
Factor out the trailing storage of call arguments, since we'll need it
for a few different kinds of expression nodes. Use it for both
CallExpr (which already had this storage, albeit with a specialized
implementation) and now SubscriptExpr.
2016-07-25 23:14:41 -07:00
swift-ci
3d1ff4dfba Merge pull request #3749 from nkcsgexi/coerce-fixit 2016-07-25 17:30:23 -07:00
Xi Ge
fc8a1d2274 [Fixit] Before applying forced cast, check if doing so leads to a warning. 2016-07-25 15:18:18 -07:00
Xi Ge
f6ef435141 [Fixit] Add a fixit to add forced cast to the contextual expected type.
This fixit helps migration. After we change some imported types to Any,
existing function calls to SDK APIs need cast to be compilable.
2016-07-25 13:40:50 -07:00
Doug Gregor
847b78245a [Type checker] Use argument labels from the expression for type-checking calls.
When we are type-checking calls, subscripts, or other call-like
expressions, use the argument labels provided by the various
expression nodes rather than those encoded in the tuple type. This
means that argument label matching now matches the callee
declaration's argument labels against the argument labels, without
relying on encoding the argument labels within types in the AST.

This refactor is a stepping stone torward SE-0111.
2016-07-25 13:27:35 -07:00
Dmitri Gribenko
d82682ec6c Merge pull request #3733 from practicalswift/typo-fixes-20160724
[gardening] Fix recently introduced typos.
2016-07-24 15:43:03 -07:00
practicalswift
7e89679404 [gardening] Fix recently introduced typos. 2016-07-24 22:32:40 +02:00
practicalswift
5c916c0e71 [gardening] "a" vs. "an"-fixes 2016-07-24 21:39:51 +02:00
Andrew Trick
ecc6bd51ad Type system support for raw pointer conversion. (#3685)
* [Type System] Handle raw pointer conversion.

As proposed in SE-0107: UnsafeRawPointer.
https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#implicit-argument-conversion

UnsafeMutablePointer<T> -> UnsafeMutableRawPointer
UnsafeMutablePointer<T> -> UnsafeRawPointer
UnsafePointer<T> -> UnsafeRawPointer
UnsafeMutableRawPointer -> UnsafeRawPointer

inout:
&anyVar -> UnsafeMutableRawPointer
&anyVar -> UnsafeRawPointer

array -> UnsafeRawPointer
string -> UnsafeRawPointer

varArray -> UnsafeMutableRawPointer

* Rename expectEqual(_, _, sameValue:) to expectEqualTest to workaround a type system bug.

<rdar://26058520> Generic type constraints incorrectly applied to functions with the same name

This is exposed by additions to the type system for UnsafeRawPointer.

Warning: unit tests fail very confusingly without this fix.
2016-07-23 11:30:49 -07:00
Doug Gregor
df5358b94b [Type checker] Allow us to find the 'callee' declaration for subscripts.
This is needed for declaration-based resolution subscript expressions,
which is the basis for implementing default arguments in subscripts as
well as declaration-based argument labels.
2016-07-21 22:01:10 -07:00
Doug Gregor
42a3e36c15 [SE-0091 Follow-up] Move !, &&, and || onto an extension of Bool.
The diagnostics changes make the compiler more robust in its diagnosis
of uses of operators defined in types.
2016-07-21 12:54:27 -07:00
swift-ci
a766e6f2d7 Merge pull request #2843 from ahoppen/SR-1236-errors 2016-07-21 10:53:11 -07:00
Rintaro Ishizaki
17ec1acdb7 [Sema] Improve diagnostic message for out of order arguments
* Argument numbers are 1 based, not starting from 0.
* Use the term `argument` consistently, `parameter` is not a term for call site.
2016-07-21 16:19:05 +09:00
Alex Hoppen
095a68b195 [Sema] Disallow accessing enum elements as instance members
This implements SE-0036.
2016-07-20 19:13:58 +02:00
Luke Larson
74e0498015 Revert "Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs."
This reverts commit 62d1fa760c.
2016-07-19 15:18:17 -07:00
Mishal Shah
62d1fa760c Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-07-19 22:31:34 +02:00
Joe
40b2c944db Add [fixit] to suggest Self.member instead of Proto.member
Protocol types cannot provide an implementation of their members — when
one is looked up on a protocol in that protocol’s context, we can
suggest using the dynamic `Self` type.

```
extension StaticP {
  func bar() {
    _ = StaticP.foo(a:)  // suggest `Self.foo(a:)`
  }
}
```
2016-07-19 20:35:27 +01:00
Mark Lacey
b2be3b3515 Merge pull request #3579 from rudkx/fix-27013358
Fix crash when using instance member as default parameter.
2016-07-18 18:19:29 -07:00
Mark Lacey
ee6c0a737b Fix crash when using instance member as default parameter.
Also produce a specific diagnostic for this case.

rdar://problem/27013358
2016-07-18 11:25:48 -07:00
Michael Gottesman
a047bb7564 Revert "Fix the build."
This reverts commit dc24c2bd34.

Turns out Chris fixed the build but when I was looking at the bots, his fix had
not been tested yet, so I thought the tree was still red and was trying to
revert to green.
2016-07-17 16:29:18 -07:00
Michael Gottesman
dc24c2bd34 Fix the build.
This reverts commit b4cba58330.
This reverts commit a602927c75.
This reverts commit 55fbe5a763.
2016-07-17 16:17:15 -07:00