Commit Graph

4105 Commits

Author SHA1 Message Date
Jordan Rose
b7e4746f85 Downgrade type access checks to warnings in certain cases.
...to be compatible with Swift 3. Fortunately these cases are all safe;
they're the cases that would all be 'fileprivate' in Swift 2.

Finishes https://bugs.swift.org/browse/SR-2579, although we'll need a
follow-up bug to turn this /back/ into an error in Swift 4.
2016-09-21 11:34:45 -07:00
Mark Lacey
401ca24532 Emit a warning when optionals are coerced to Any.
Emit a warning for optionals that are implicitly converted to Any, and
add fixits giving options to:
- Add '??' with a default value after
- Force-unwrap the optional with '!'
- Explicitly cast to 'as Any' to silence the warning

This covers diagnostics aspect of SE-0140.

rdar://problem/28196843
2016-09-20 22:33:45 -07:00
Jacob Bandes-Storch
682ab47c2d [QoI] diagnose operator fixity attrs together; improve messages
Previously, `infix` was not recognized as conflicting with `prefix` and `postfix`. We now offer to remove all but the first fixity attribute.
2016-09-20 20:54:07 -07:00
practicalswift
b19481f887 [gardening] Fix 67 recently introduced typos 2016-09-16 11:16:07 +02:00
Slava Pestov
90d6e8dce8 Sema: Variadic parameters are always @escaping and cannot be @autoclosure
A variadic parameter of function type must be @escaping -- we cannot
reason about an array of non-escaping closures, so this was a safety
hole.

Also, attempting to define an @autoclosure variadic did not produce a
diagnostic, but would fail later on if you actually tried to do
anything with it. Let's ban this completely.

Both changes are source breaking, but impact is limited to code that
was already only marginally valid.
2016-09-15 21:46:02 -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
Mishal Shah
10ca65aac8 Merge pull request #4684 from milseman/escaping
[noescape-by-default] Diagnostic notes for closure type arguments
2016-09-09 15:47:39 -07:00
Mishal Shah
9bb7644a69 Merge pull request #4419 from milseman/no_factory
[Import as Member] Error on convenience inits in extensions of CFTypes
2016-09-09 14:28:28 -07:00
Michael Ilseman
585716387c [noescape-by-default] Diagnostic notes for closure type arguments
Adds in helpful notes when a closure type argument is already
escaping, and thus doesn't need annotation. The common case targeted
now is Optional and IUO, which is the biggest bang for our buck
without needlessly complicating the type options.

Test cases included for the new note, and potential interactions.

In the future we'd like some kind of parent pointer, or context stack
to give better diagnostics universally. For now, we hack it by having
ImmediateOptionalTypeArgument as a special flag.
2016-09-09 13:00:21 -07:00
John McCall
34fb15e375 Abstract the object type of an optional type according to the
abstraction pattern of the type rather than always using the
most-general pattern, and erase ImplicitlyUnwrappedOptional from
the SIL type system.
2016-09-08 23:26:19 -07:00
Michael Ilseman
c16f8919d8 [escaping] Correct diagnostic for parameter position
In situations where @escaping is used in non-function-parameter
positions, we give an incorrect diagnostic message pertaining to
function types. Instead, we should just state that this is not allowed
in non-function-parameter positions.

This includes the general message fix. Unfortunately, this does not
include more friendly messages for special cases, e.g. closure members
of aggregate and optional closures. That may be possible with more
nested type context information in TypeCheckType.
2016-09-07 15:38:20 -07:00
Slava Pestov
1487d590a9 Merge pull request #4617 from slavapestov/kill-canonical-mangling-signature
Kill canonical mangling signature
2016-09-06 13:44:25 -07:00
Rintaro Ishizaki
a7fef2299f Merge pull request #4627 from rintaro/nowitness-stub
[Sema] Improve fix-it for missing initializer requirement
2016-09-07 04:10:19 +09:00
Slava Pestov
9771ec84dd Sema: Improve checking of associated type superclass constraints
When checking a conformance of a concrete type to a protocol, we
effectively checked the associated types twice -- once when
deriving them, and another time at the end, where we performed
a substitution of the protocol 'Self' type to the concrete type.

The latter checked superclass constraints, while the former did not.

However, this trick no longer works with minimized generic
signatures, because <P : Self> no longer has redundant requirements
for the associated types of 'P'.

Instead, check superclass constraints at the same time as checking
conformances.
2016-09-06 11:51:14 -07:00
Doug Gregor
db5f8c326d Merge pull request #4540 from jtbandes/qoi-contextual-member
[QoI] improve diagnostics for contextual members with argument mismatch
2016-09-06 08:44:06 -07:00
Rintaro Ishizaki
f585a270f9 [Sema] Improve fix-it for missing initializer requirement
* If current context is extension of non-final class, don't suggest stub
* If current context is extension of final class, insert 'convenience'
* If current context is direct definition of non-final class, insert 'required'
2016-09-05 18:13:05 +09:00
Jacob Bandes-Storch
bc3a7d1241 [QoI] improve diagnostics for contextual members with argument mismatch 2016-08-28 15:59:41 -07:00
Dave Abrahams
5c13e35f29 [stdlib] Suppress noisy warnings
We don't have a way yet to say "this is deprecated for users, but let
the stdlib use it without complaining" so we need to do refactoring
shenanigans.
2016-08-28 15:06:42 -07:00
Slava Pestov
1705caaf72 Merge pull request #4038 from karwa/generic-enums
Fix SR-2134: emit 'rawValue' bodies for enums with a generic raw value
2016-08-23 21:52:50 -07:00
Jordan Rose
4372a30147 Operator methods are not @objc-compatible. (#4430)
https://bugs.swift.org/browse/SR-2419
2016-08-23 13:36:56 -07:00
Michael Ilseman
1593c2aeeb [Import as Member] Error on convenience inits in extensions of CFTypes
Swift does not currently support user-defined factory inits. With
import as member, we're seeing many C functions now imported as
initializers, which gives users the false hope that they can define
their own factory inits as conveinence inits in extensions of CF
types. We issue an explicit error now, rather than crashing later.
2016-08-23 10:53:30 -07:00
SpringsUp
f9af1257ef Tighter type-checking of enums with synthesized RawRepresentable
conformance
Fixes SR-2134
2016-08-22 22:49:48 +02:00
Doug Gregor
fe7e780559 Remove -Womit-needless-words; it was a hack to bring up the Grand Renaming.
I'm slightly sad about losing the lovely code to detect
redundantly-specified defaulted arguments, but we could bring it back
later as a separate warning.
2016-08-19 14:19:51 -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
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
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
Slava Pestov
a21c748fee Sema: Fix crash on Linux if ObjCBool type is not present 2016-08-10 10:34:24 -07:00
Doug Gregor
a15c485193 [SE-0091] Require member operators to refer to the enclosing nominal type.
Member operators should be placed within a nominal type (or extension
thereof) that they operate on. Aside from being good style, enforcing
this in the type checker can help with dependency tracking. Addresses
rdar://problem/27536066.
2016-08-08 23:26:35 -04:00
Xi Ge
e80a807f4c Merge remote-tracking branch 'apple/master' into pointer-diagnosis 2016-08-08 16:00:09 -07:00
Xi Ge
7ae8f65d7f [test] Updating existing test. NFC 2016-08-08 15:08:09 -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
Xi Ge
b3cbac149a Use one parameter in the diagnosis message instead of two. NFC 2016-08-08 12:57:07 -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
91184e1212 [FixCode] Add a diagnosis/fixit to help users convert Unsafe[Mutable]Pointer<Void> to Unsafe[Mutable]RawPointer. rdar://27730408 2016-08-08 12:23:25 -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
Robert Widmann
e63ac0f72b Merge pull request #4019 from harlanhaskins/imported-goods
Improve nonexistent decl diagnostic
2016-08-07 10:25:03 -07:00
practicalswift
c69a5c754e Remove unused diagnostics. 2016-08-06 12:36:32 +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
Michael Ilseman
1d305f8ac8 Adjust diagnostic: s/@noescape/non-escaping/ 2016-08-04 18:14:00 -07:00
Harlan Haskins
5557ec2bbc Improve nonexistent decl diagnostic 2016-08-04 14:28:49 -07:00
Chris Lattner
1d21b4e4e1 Add a bit and some diagnostics logic to help with the ongoing id-as-any project.
This is NFC because nothing sets the bit yet, it is just to aid an ongoing
investigation.
2016-08-03 16:45:01 -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
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
Doug Gregor
212ffadf5e Improve diagnostic for Error compositions not being representable in Objective-C.
Thanks, Jordan!
2016-08-02 10:21:01 -07:00
Doug Gregor
6575877124 [@objc checking] Only 'Error' is representable in Objective-C (as 'NSError').
Don't allow types conforming to 'Error' or protocol compositions
involving 'Error' to be reflected in Objective-C. We still allow
bridging conversions, but they are not statically bridged. Fixes
SR-2249/rdar://problem/27658940.
2016-08-02 10:13:54 -07:00