Commit Graph

1092 Commits

Author SHA1 Message Date
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
Chris Lattner
55fbe5a763 Remove Boolean as a special, privileged type used by Sema, and instead
use the concrete Bool type.  This eliminates a bunch of complexity and
makes diagnostics more concrete.
2016-07-17 15:14:24 -07:00
Chris Lattner
a0d34852bb Revert "Fix the build."
This reverts commit 932fe9d6b9.
2016-07-17 12:35:42 -07:00
Michael Gottesman
932fe9d6b9 Fix the build.
This reverts commit 4242af7503.
This reverts commit 76cf339694.
This reverts commit e97ed133a8.
This reverts commit 66961fcda8.
2016-07-17 01:02:48 -07:00
Chris Lattner
76cf339694 Implement the first half of SE-0109: Remove the Boolean protocol
This removes conformance of DarwinBool and ObjCBool to the Boolean protocol,
and makes the &&/||/! operators be concrete w.r.t. Bool instead of abstract
on Boolean.

This fixes some outstanding bugs w.r.t diagnostics, but exposes some cases
where an existing diagnostic is not great.  I'll fix that in a later patch
(tracked by rdar://27391581).
2016-07-16 23:23:45 -07:00
Doug Gregor
5a83c86455 Eliminate default arguments from TupleType.
In Swift, default arguments are associated with a function or
initializer's declaration---not with its type. This was not always the
case, and TupleType's ability to store a default argument kind is a
messy holdover from those dark times.

Eliminate the default argument kind from TupleType, which involves
migrating a few more clients over to declaration-centric handling of
default arguments. Doing so is usually a bug-fix anyway: without the
declaration, one didn't really have

The SILGen test changes are due to a name-mangling fix that fell out
of this change: a tuple type is mangled differently than a non-tuple
type, and having a default argument would make the parameter list of a
single-parameter function into a tuple type. Hence,

  func foo(x: Int = 5)

would get a different mangling from

  func foo(x: Int)

even though we didn't actually allow overloading.

Fixes rdar://problem/24016341, and helps us along the way to SE-0111
(removing the significance of argument labels) because argument labels
are also declaration-centric, and need the same information.
2016-07-15 13:55:53 -07:00
Mark Lacey
86c97dfbb5 Merge pull request #3483 from rudkx/fix-nil-comparisons
Improve diagnostics for comparisons to nil.
2016-07-13 11:50:06 -07:00
Mark Lacey
1d9fde8f5c Improve diagnostics for comparisons to nil.
As implemented the diagnostic specific to nil was only firing when nil
was on the right hand side.
2016-07-12 17:21:12 -07:00
Robert Widmann
f97e5dcb0e [SE-0115][1/2] Rename *LiteralConvertible protocols to ExpressibleBy*Literal. This
change includes both the necessary protocol updates and the deprecation
warnings
suitable for migration.  A future patch will remove the renamings and
make this
a hard error.
2016-07-12 15:25:24 -07:00
Alex Hoppen
c8ec2c0a2b [Diag] Fixit when trying to pattern match Optional and non-Optional
If the variable to be matched is an optional and the match partner is
non-optional, provide a fixit that inserts a '?' after the match partner
2016-07-11 16:27:57 +02:00
Alex Hoppen
fc4216e94b [Sema] Don't suggest fixits that try to force unwrap implicit $match
Check if a variable is actually spelled out in code before suggesting a
fixit that adds a force unwrap to it

This fixes SR-1827
2016-07-11 16:27:57 +02:00
Han Sangjin
cccfbf4d3c [swiftc/msvc] Compiling with MSVC (#1516)
Some modifications for the ms-extension option of the clang.exe in the Visual Studio 2015 development environment

This patch is only for swiftc.exe. I used the library set of Visual Studio 2015 Update 1 and recent version of swift-clang as the compiler. If you are using the real MSVC compiler, more patch might be required.
2016-07-08 19:06:10 -07:00
swift-ci
3d0252ae77 Merge pull request #3307 from rjmccall/typo-correction-for-qualified-lookup 2016-07-05 10:40:00 -07:00
Chris Lattner
e0fcec578d When evaluating candidates for closeness, make sure to consider UnresolvedType to be
a match, since it *could* be, and typically conforms to whatever the expression is.

Fixing this improves the diagnostic in Constraints/closures.swift significantly, and
fixes these bugs:
<rdar://problem/21718970> QoI: [uninferred generic param] cannot invoke 'foo' with an argument list of type '(Int)'
<rdar://problem/21718955> Swift useless error: cannot invoke 'foo' with no arguments

where before we produced:
error: cannot invoke 'foo' with an argument list of type '(Int)'

and now produce:

x.swift:5:10: error: generic parameter 'A' could not be inferred
Whatever.foo(a: 23)
         ^
x.swift:1:7: note: 'A' declared as parameter to type 'Whatever'
class Whatever<A: IntegerArithmetic, B: IntegerArithmetic> {
      ^
2016-07-03 15:18:58 -07:00
John McCall
6593c5319d Add typo correction to qualified lookup. 2016-07-01 19:04:57 -07:00
gregomni
27b7420fff Fix for crash 28290 in findGenericSubstitutions
Early out needs to check that the types don’t contain UnresolvedType,
not just that they aren’t UnresolvedType at the top level.
2016-07-01 10:48:50 -07:00
Rintaro Ishizaki
f895326200 [Sema][SE-0060] Add fix-it for out-of-order arguments 2016-06-29 16:25:04 +09:00
Harlan
cca7dcab52 Added fixit to remove empty argument for non-function calls (#3196) 2016-06-26 17:06:26 -07:00
Xi Ge
f727ec0cf2 [Fixit] Suggested by Jordan, check immutability before adding ampersand. 2016-06-22 14:47:23 -07:00
Slava Pestov
3a043a25e1 Sema: Hacky fix for a crash in CSDiag
It looks like the mapTypeIntoContext() call is using the wrong
'dc', because in fact we have no way of knowing what the original
'dc' was which produced the type parameters in question.

Really the problem is we're picking apart SubstitutedType here,
which is almost always the wrong thing to do. I don't think
SubstitutedType should exist at all.

To avoid the crash, just bail-out if 'dc' is not generic.

I'm intentionally avoiding a principled fix here to hasten the
apocalypse when all of CSDiag.cpp will collapse under its own
weight and get rewritten in a sane way.
2016-06-21 16:25:29 -07:00
Xi Ge
b378e38170 [Fixit] Also add & to bridge T and UnsafeMutablePointer<T>. 2016-06-21 14:25:04 -07:00
Xi Ge
f19e6cba03 [Fixit] Suggested by Dmitri, adding & instead of [] to bridge T and UnsafePointer<T>. 2016-06-21 14:16:50 -07:00
Xi Ge
3a6baaf83b [Fixit] Provide fixit when converting expressions of type T to [T] or UnsafePointer<T>. 2016-06-21 13:10:21 -07:00