Commit Graph

664 Commits

Author SHA1 Message Date
Doug Gregor
49b833b51a [Type checker] Eliminate the 'literalConformanceProto' state on type variables.
The 'literalConformanceProto' field of
TypeVariableType::Implementation didn't take into account equivalence
classes of type variables. Eliminate it, and either look at the actual
expressions (for optimizing constraints during constraint generation)
or the actual constraints on a given type variable (for determining
whether to include optionals in the set of potential type variable
bindings).

(cherry picked from commit 6bdd9cfae5)
2016-10-13 16:22:01 -07:00
Doug Gregor
01fa24cc9b Speculatively revert "[Type checker] Eliminate the 'literalConformanceProto' state on type variables."
This reverts commit 6bdd9cfae5. This
commit *appears* to be breaking something in Dollar involving
inference with array literals and 'nil'; pull it back for more
investigation.
2016-10-12 09:20:16 -07:00
Robert Widmann
f59d5cb577 Normalize the way paren types are stripped in Sema. 2016-10-12 00:00:39 -04:00
Doug Gregor
6bdd9cfae5 [Type checker] Eliminate the 'literalConformanceProto' state on type variables.
The 'literalConformanceProto' field of
TypeVariableType::Implementation didn't take into account equivalence
classes of type variables. Eliminate it, and either look at the actual
expressions (for optimizing constraints during constraint generation)
or the actual constraints on a given type variable (for determining
whether to include optionals in the set of potential type variable
bindings).
2016-10-11 17:09:13 -07:00
Doug Gregor
c2b9759cd3 Simplify ConstraintSystem::getFixedTypeRecursive and use it consistently.
We had a few places that were performing ad hoc variants of
ConstraintSystem::getFixedTypeRecursive(); simplify it's interface so
we can use it everywhere consistently. Fixes rdar://problem/27261929.
2016-10-11 17:08:52 -07:00
Doug Gregor
ab959c9f21 Introduce TypeBase::isTypeVariableOrMember(). NFC
Similar to “isTypeParameter,” this new entry point determines whether the type is a type variable or a nested type of a type thereof. The latter case isn’t actually formed yet, so this is NFC staging the trivial bits of this change.
2016-10-11 11:38:52 -07:00
swift-ci
d38198bd68 Merge pull request #5063 from graydon/rdar-27982012-poor-diagnostic 2016-10-07 17:56:00 -07:00
Doug Gregor
50341da32b Use "TypeBase::hasError()" rather than "is<ErrorType>()" where needed.
In most places where we were checking "is<ErrorType>()", we now mean
"any error occurred". The few exceptions are in associated type
inference, code completion, and expression diagnostics, where we might
still work with partial errors.
2016-10-07 10:58:23 -07:00
Graydon Hoare
0d5420b7dd In CSDiag, diagnose callee inaccessibility before digging into args.
Fixes QoI rdar://problem/27982012
2016-10-07 09:35:03 -07:00
Slava Pestov
354416f912 AST: Kill Type::getAllGenericArgs()
This was almost identical to getMemberSubstitutions(), except
protocol and protocol extension members are not properly
supported.

Now that this method is no longer used by the ASTPrinter, there
are only two remaining usages, both trivially refactorable to
use better APIs.
2016-10-03 00:39:49 -04:00
Rintaro Ishizaki
65f3ba5dbb [Sema] Unify fix-it logic for enclosing trailing closure in argument parens (#4961)
`tryDiagnoseTrailingClosureAmbiguity` and `checkStmtConditionTrailingClosure`
had similar logic.
Added swift::fixItEncloseTrailingClosure function.
2016-09-24 18:33:40 +09:00
Pavel Yaskevich
054e3e4eb4 [Diagnostics] SR-2242: Fix diagnostic when argument label is omitted 2016-09-23 17:17:59 -07:00
Pavel Yaskevich
2dfc8b60ad [Diagnostics] Refactor argument source range retrieval 2016-09-23 15:14:21 -07:00
Pavel Yaskevich
f0078d6bc3 [Diagnostics] Refactor argument matching when dealing with a single candidate 2016-09-23 15:14:21 -07:00
Slava Pestov
a9c68c0736 AST: Remove archetype from AbstractTypeParamDecl
There's a bit of a hack to deal with generic typealiases, but
overall this makes things more logical.

This is the last big refactoring before we can allow constrained
extensions to make generic parameters concrete. All that remains
is a small set of changes to SIL type lowering, and retooling
some diagnostics in Sema.
2016-09-22 19:48:30 -07:00
swift-ci
675e542f3b Merge pull request #4939 from rudkx/fix-27830834 2016-09-22 18:02:09 -07:00
Jordan Rose
b9e1d4c21c Don't use construction to convert literals in rawValue fix-it. (#4934)
Input:  panel.styleMask = 8345
Old output:  panel.styleMask = NSWindowStyleMask(rawValue: UInt(8345))
New output:  panel.styleMask = NSWindowStyleMask(rawValue: 8345)

rdar://problem/26681232
2016-09-22 17:36:41 -07:00
Mark Lacey
b44a93ea84 Fix crash on typecheck failure in interpolated strings.
We were attempting to clean up stray type variables before creating a
new constraint system and moving forward with narrowing down the
typecheck failure, but we were failing to remove type variables for
interpolated strings.

Fix that, as well as removing them from TypeExpr's, and add an assert
that on exit from the pre-order visitor we don't have any type
variables (except for literals that aren't interpolated strings, which
I'm going to dig into further).

Fixes rdar://problem/27830834 and SR-2716.
2016-09-22 17:09:31 -07:00
Michael Ilseman
4324d8f4b0 [CSDiag] Switch to using the ASPrinter rather than repeating logic 2016-09-22 13:19:22 -07:00
Jordan Rose
821cdf368d Merge pull request #4910 from jrose-apple/fix-it-swift_newtype-rawValue
Use the existing '.rawValue' fix-it to handle unwrapping objects too.

rdar://problem/26678862
2016-09-21 18:28:40 -07:00
Jordan Rose
693fd9d455 Use the existing '.rawValue' fix-it to handle unwrapping objects too.
We could probably make this even more general, but this specifically
avoids trying to insert an "as AnyObject" fix-it, which will now work
but probably produce an incorrect result. This comes up when working
with swift_newtype wrappers of CF types being passed to CFTypeRef
parameters.

rdar://problem/26678862
2016-09-21 17:16:26 -07:00
Jordan Rose
caeed32302 Add a fix-it for missing generic parameters on construction.
For example, if someone tries to use the newly-generic type Cache,
from Foundation:

  var cache = Cache()

they'll now get a fix-it to substitute the default generic parameters:

  var cache = Cache<AnyObject, AnyObject>()

The rules for choosing this placeholder type are based on constraints
and won't be right 100% of the time, but they should be reasonable.
(In particular, constraints on associated types are ignored.)
In cases where there's no one concrete type that will work, an Xcode-
style placeholder is inserted instead.

- An unconstrained generic parameter defaults to 'Any'.
- A superclass-constrained parameter defaults to that class,
  e.g. 'UIView'.
- A parameter constrained to a single @objc protocol (or to AnyObject)
  defaults to that protocol, e.g. 'NSCoding'.
- Anything else gets a placeholder using the generic parameter's name
  and protocol composition syntax.

rdar://problem/27087345
2016-09-21 18:04:14 -06:00
Jordan Rose
6bc61fe8ce Fix a fix-it to cast to the destination type, not the source type.
Copy/paste issue, most likely.
2016-09-21 16:40:40 -07:00
Slava Pestov
ced715cb46 Sema: Fix crash when attempting to diagnose a contextual conversion of an ambiguous expression
The fixits call back into the type checker via typeCheckCheckedCast(),
which sets up a new constraint system. As a result we would hit
assertions by introducing type variables from a previous "generation".

It seems that if we bail out of this code path altogether, we get a
better diagnostic -- in the provided test, it complains about an
ambiguous member to '.value', rather than not being able to convert
_? to V?.

Fixes <https://bugs.swift.org/browse/SR-2592>.
2016-09-19 17:53:05 -07:00
Jordan Rose
e6d6e0e92f Offer fix-its to disambiguate based on a trailing closure's label.
(by making it a normal argument with a label and not a trailing
closure)

Diagnostic part of rdar://problem/25607552. A later commit will keep
us from getting in this situation quite so much when default arguments
are involved.
2016-09-15 11:05:02 -07:00
Jordan Rose
a14e3291ce Say "ambiguous use of 'foo'" instead of "'foo(bar:)'".
...unless the argument labels are the same for every possible
overload.

Only affects diagnostics.
2016-09-15 10:38:44 -07:00
Jacob Bandes-Storch
bc3a7d1241 [QoI] improve diagnostics for contextual members with argument mismatch 2016-08-28 15:59:41 -07:00
Andrew Trick
580372b98b [diagnostics] Emit a a note for optional conversion of raw pointers. (#4442)
In CSDiag.cpp I previously added a helper, isCastToTypedPointer(), to emit an
diagnostics explaining how to migrate UnsafeRawPointer conversion. This commit
broadens that diagnostic to handle Optional<UnsafeRawPointer>.

rdar:27894255 [3.0 migration] Emit an additional note for conversion
2016-08-20 21:11:50 -07:00
Slava Pestov
8a67d71de0 Sema: Look through TryExpr in FailureDiagnosis
This fixes a case where we would produce the generic 'ambiguous without
more context' error when a 'try' was present.

Fixes <rdar://problem/27891805>.
2016-08-19 16:01:38 -07:00
Xi Ge
52273554f4 [FixCode] Add diagnosis/fixit to help users deal with BooleanType's removal (#4392)
* [FixCode] Add diagnosis/fixit to help users deal with BooleanType's removal.

Due to migration reasons, types used to conform to BooleanType, which
must contain a member var 'boolValue', now does not convert to Bool. This patch
adds a specific diagnosis/fixit to explicitly invoke 'boolValue' to please the
context types.

* Address Jordan's code review comments.
2016-08-19 08:29:42 -07:00
Xi Ge
2ebab526bf [FixCode] Apply coercion fixits on return statement and initialization as well. rdar://27891589 rdar://27891426
We saw manual migration is necessary on these cases to add 'as Type'. This patch starts
to issue compiler fixits on return statement and initialization just like in other type-mismatch
cases.
2016-08-18 13:21:44 -07:00
Doug Gregor
65d8f03448 Merge pull request #4329 from rjmccall/collection-upcast-oves
Fix this to not die on the OVEs from collection upcasts.
2016-08-17 10:40:56 -07:00
John McCall
e360d7f2b0 Fix the open-existential remover to not die on the OVEs in collection upcasts. 2016-08-16 22:17:02 -07:00
Xi Ge
b620d3ebfe [FixCode] Apply coercion fixit for assignment types' mismatch too. rdar://27681428 2016-08-16 14:28:18 -07:00
Paul Meng
e172383e2f [Sema] Implement SE-0110
This commit built upon the work of Pull Request 3895. Apart from the
work to make the following work

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

This patch also implement the part 2 mentioned in the #3895

```swift
let g: ((Int, Int)) -> Void = { y in  } // y should have type (Int, Int)
```
2016-08-14 12:02:27 +08:00
Michael Ilseman
97e4e2abe5 [noescape-by-default] Improve diagnostics.
This makes the special case diagnostics for detecting a missing
@escaping read through Optional and IUOs.
2016-08-12 17:06:12 -07:00
Mark Lacey
96f89384c4 Merge pull request #4245 from rudkx/fix-27449208
Special-case error for indexing into a nil literal.
2016-08-11 16:09:09 -07:00
Jordan Rose
148e25dc03 Provide the '@escaping' fix-it for any call-site escaping mismatch. (#4181)
...not just those where the functions match otherwise. This allows the
fix-it to be provided in cases where the closure being passed is a
subtype, or when there are generics involved. Yes, the '@escaping'
might not be the only issue, but it will need to get fixed, and
probably independently of anything else that's going on (except
perhaps calling the wrong function).

rdar://problem/27729540
2016-08-11 14:32:36 -07:00
Mark Lacey
753642e005 Special-case error for indexing into a nil literal.
We were previously crashing at some later point in diagnostic emission.

Resolves rdar://problem/27449208.
2016-08-11 14:32:21 -07:00
Slava Pestov
a485e525c5 Sema: Allow protocol typealiases to be accessed from expression context, as long as they don't depend on 'Self'
Suppose you have this protocol:

protocol P {
  typealias A = Int
  typealias B = Self
}

Clearly, 'P.B' does not make sense, because then the type parameter
would "leak out" of the existential container. However, 'P.A' is totally
fine, it just means 'Int'.

Previously, we would allow 'P.A' in type context, and diagnose on 'P.B'.

However, due to an oversight, neither one was allowed in expression
context, so for example you could not write 'P.A.self', even though
that should just mean 'Int.self'.

Fix this by generalizing performMemberLookup(), and fix up some
diagnostics to be more specific when something is wrong -- we want
to avoid talking about typealiases as 'static members', since that
doesn't really make much sense.

Fixes <https://bugs.swift.org/browse/SR-2314>.
2016-08-10 23:23:24 -07:00
Ted Kremenek
1d36ed9ed3 Merge pull request #4116 from rudkx/fix-27639935
Make fix for dynamic lookup on Any work for more general expressions.
2016-08-08 17:01:04 -07:00
Ted Kremenek
92f0d9ea30 Merge pull request #4114 from atrick/rawptr-diag
Improve diagnostics on invalid UnsafePointer conversion.
2016-08-08 14:23:49 -07:00
Mark Lacey
4f5b80dd03 Make fix for dynamic lookup on Any work for more general expressions.
Follow-up to 56a5ef00a4.

Thanks to Jordan for noticing and suggesting this!

rdar://problem/27639935
2016-08-08 12:59:56 -07:00
Andrew Trick
56f68c4cce Improve diagnostics on invalid UnsafePointer conversion.
The only remaning issue is that we should have a warning to rename
Unsafe[Mutable]Pointer<Void> to Unsafe[Mutable]RawPointer.
2016-08-08 12:54:21 -07:00
Xi Ge
a0c7f51e10 Addressing Jordan's code review feedbacks. NFC 2016-08-08 11:00:23 -07:00
Mark Lacey
62c814a86f Merge pull request #4078 from rudkx/fix-27639935
Add a fixit for attempting member lookup on Any.
2016-08-07 15:28:57 -07:00
Mark Lacey
56a5ef00a4 Add a fixit for attempting member lookup on Any.
Suggest casting to AnyObject or a more specific type.

rdar://problem/27639935
2016-08-07 12:19:53 -07:00
practicalswift
0661f61578 Use a-vs-an consistently. 2016-08-06 12:41:55 +02:00
Xi Ge
7afe4cc96d [FixCode] Add a fixit to help users migrate to Swift 3 name convention. (#4058)
* [FixCode] Add a fixit to help users migrate to Swift 3 name convention of enum cases. rdar://26887735

When users' referring to a enum case with a wrong name and we can find a correct enum case whose name
differs from the wrong name only in capitalization, we replace the wrong name with the correct one.

* Addressing Argyrios' code review comments. NFC

* [test] Update existing test.

* Grammatical polish suggested by @CodaFi.
2016-08-05 20:59:26 -07:00
Slava Pestov
22aa032285 Sema: Clean up SE-0036 diagnostic a bit
Suggest a fix-it for unqualified references to all static members
from instance context, not just enum elements.

Also, fix a small problem with the fix-it for replacing protocol
names with 'Self' inside extension bodies -- we didn't handle nested
functions properly.
2016-08-05 14:27:16 -07:00