Commit Graph

995 Commits

Author SHA1 Message Date
Slava Pestov
f6e692198c AST: Remove FuncDecl::getResultType() 2016-11-29 03:05:23 -07:00
Rintaro Ishizaki
cdcbc2d2e0 [QoI] When adding '.self' for metatype expressions, enclose with parenthesis if the typerepr is not Simple 2016-11-29 15:28:48 +09:00
Rintaro Ishizaki
af19a0bd50 [Diag] Suggest adding '()' only if it has accessible initializers 2016-11-29 15:28:48 +09:00
Graydon Hoare
7c1dc18b64 Revert "Give all declarations an explicit interface type" 2016-11-24 09:55:27 -08:00
Slava Pestov
5b8524a9d1 AST: Remove FuncDecl::getResultType() 2016-11-24 02:35:35 -05:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Jordan Rose
a7b027df92 Merge pull request #4579 from aleksgapp/sr-2209-access-scope
[SR-2209] Add real AccessScope type.
2016-11-11 11:16:12 -08:00
practicalswift
17503b0d85 [gardening] Use American English. 2016-11-06 10:12:04 +01:00
Rintaro Ishizaki
f4a9898142 [QoI] Improve "never used" diagnostics (#5638)
On 'let (x) = some', we should remove r-paren as well.
On 'let x: Int = some', we can't remove 'let' introducer.
2016-11-05 15:17:54 +09:00
Aleksey Gaponov
f51b2d12c4 [SR-2209] Make a real AccessScope class and use it in access checking.
1. Add new AccessScope type that just wraps a plain DeclContext.
2. Propagate it into all uses of "ValueDecl::getFormalAccessScope".
3. Turn all operations that combine access scopes into methods on AccessScope.
4. Add the "private" flag to distinguish "private" from "fileprivate"
scope for top-level DeclContext.
2016-11-04 12:42:38 +01:00
Mark Lacey
93f9f8b696 Warn on string interpolation of optional lvalues.
We were only warning when the desugared type was an optional, without
first stripping off the lvalue-ness.

Resolves rdar://problem/27435494.
2016-11-01 14:43:01 -07:00
Xiaodi Wu
185a73e542 Refactor diagnoseMemoryLayoutMigration [NFC] 2016-10-24 18:27:54 -05:00
Graydon Hoare
098c42ede8 Add missing EncodedDiagnosticMessage wrapper. 2016-10-12 11:21:30 -07:00
Graydon Hoare
cec8f58197 Add swift::diagnoseDeclAvailability, use in TypeCheckType. 2016-10-12 11:21:30 -07:00
Graydon Hoare
77df25d892 Generalize AvailableAttr MinVersion checks to cover language versions. 2016-10-12 11:20:44 -07:00
Graydon Hoare
42c1a6ce42 Rename UnconditionalAvailabilityKind and UnavailableInCurrentSwift.
UnconditionalAvailabilityKind => PlatformAgnosticAvailabilityKind
    ::UnavailableInCurrentSwift =>   ::SwiftVersionSpecific

Plus a couple related method renamings. Prep work for SR-2709.
2016-10-12 11:20:41 -07:00
Robert Widmann
f59d5cb577 Normalize the way paren types are stripped in Sema. 2016-10-12 00:00:39 -04:00
Robert Widmann
975e2db702 fix a misleading comment 2016-10-11 22:40:11 -04:00
Robert Widmann
f7984f86a6 Improve diagnostics for optionals in string interpolation segments 2016-10-11 12:27:09 -04:00
Mark Lacey
5356cc37bd Fix a couple cases of ArrayRef capturing compiler temps.
Use a SmallVector for scratch space to use to build the ArrayRefs
instead.
2016-10-07 16:06:23 -07:00
swift-ci
edd2ecdf0c Merge pull request #5177 from DougGregor/error-type-with-original 2016-10-07 12:14:38 -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
Robert Widmann
024349788e General bike shedding 2016-10-04 10:09:56 -04:00
Robert Widmann
43a582ef0f Initial implementation of optionals-in-string-interpolation warnings
Basic extension of the optional-to-any AST walker to incorporate
warnings for the as-of-now up and coming Swift evolution proposal.
2016-10-03 17:08:11 -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
Jordan Rose
d89c232f59 Add empty parens to var-to-function renames, take two. (#4938)
This time, propagate the decl marked deprecated or unavailable through
to the fix-it, so we can be sure it's a var.

https://bugs.swift.org/browse/SR-1649
2016-09-23 14:56:08 -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
Jordan Rose
ff4f2ce47f Revert "Add empty parens to var-to-function renames" (#4930)
"!call" doesn't imply "variable", so the fix-it isn't always correct.

This reverts commit a99ca851df (#3947).
2016-09-22 16:12:23 -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
Mark Lacey
d8135798eb Improvements to optional-to-Any coercion warning.
Don't explicitly desguar types when it is not needed and/or results in
worse types displayed in diagnostics.

Tweak the warning messages to use "this warning" rather than "the
warning".

Addresses feedback from Jordan on commit 401ca24532.
2016-09-21 13:27:52 -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
practicalswift
b19481f887 [gardening] Fix 67 recently introduced typos 2016-09-16 11:16:07 +02:00
Jordan Rose
9e79e0b362 Provide a fix-it when overriding 'Any' with 'AnyObject'. (#4729)
This helps when manually migrating Swift 2 code to Swift 3, which
includes SE-0116 (id-as-Any). We already did this for specific bridged
types (like URL and NSURL); this just adds a special case for
Any/AnyObject.

rdar://problem/27865590
2016-09-12 17:19:53 -07:00
Doug Gregor
68c3f3b1b3 Remove EnableSwift3Private staging option. 2016-08-19 21:53:32 -07:00
Doug Gregor
51529ae888 Eliminate the -enable-id-as-any flag; it's always on now anyway.
Simplify e.g., ASTContext::getBridgedToObjC(), which no longer needs
the optional return.

Eliminate the now-unused constraint kind for checking bridging to
Objective-C.
2016-08-19 21:17:09 -07: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
Harlan Haskins
96ff4528c4 Special-case constructor calls in MiscDiagnostics. 2016-08-13 09:37:26 -07:00
Xi Ge
a2b837300a Address @jrose-apple's code review comments. (#4278)
* Address Jordan's code review comments

* [test] Add test case for generic function types.
2016-08-12 19:45:33 -07:00
Xi Ge
b58c3a2fb7 [FixCode] Add @escaping when overriding mismatch is because of it. (#4273)
* [FixCode] Add @escaping when overriding mismatch is because of it. rdar://27814862

With the change of default escaping behavior, users' existing code overriding
objc functions may need to add @escaping to make the overriding match as before. This
patch checks if an overriding mismatch is due to the lacking of @escaping and add
it as a fixit.

* [test] Update existing test. NFC
2016-08-12 15:43:48 -07:00
Dave Abrahams
e6dec58cc5 Merge pull request #4041 from xwu/memory-layout-of-value
[stdlib] Implement SE-0136 (Restore MemoryLayout.*(ofValue:))
2016-08-12 11:09:17 -07:00
Jordan Rose
f65ad810df Check protocol witnesses using access scopes. (#4176)
...rather than relying on the access-as-spelled, which may be greater
than the effective access due to parent scopes.

(Some of this will get cleaned up with SR-2209.)

rdar://problem/27663492
2016-08-11 14:30:09 -07:00
Jordan Rose
38e6b2808e Do even less availability checking under -disable-availability-checking. (#4214)
...and make sure we're in that mode for SIL inputs and for sil-opt and
sil-extract, even when working with AST types and declarations rather
than SIL types.

Without this, we get zillions of deprecation warnings coming out of
the validation tests SIL/parse_stdlib_*.sil, which dump the standard
library and then attempt to re-parse it. This has been causing the
"long" tests to take, well, too long.
2016-08-11 10:19:46 -07:00
Robert Widmann
4b41a7fdee Merge pull request #3947 from harlanhaskins/you-know-claremont-street
Add empty parens to var-to-function renames
2016-08-09 13:56:04 -07:00
Xiaodi Wu
f9435b9ce8 [stdlib] Restore MemoryLayout.*(ofValue:) 2016-08-08 10:46:37 -05:00
Doug Gregor
22287ddb58 [Type system] Infer 'Any' for array elements and dictionary values and 'AnyHashable' for dictionary keys.
The id-as-Any work regressed cases where Swift code could specify
heterogeneous collection literals, e.g.,

    var states: [String: Any] = [
      "California": [
        "population": 37_000_000,
        "cities": ["Los Angeles", "San Diego", "San Jose"],
      ],
      "Oregon": [
        "population": 4_000_000,
        "cities": ["Portland", "Salem", "Eugene"],
      ]
    ]

Prior to this, the code worked (when Foundation was imported) because
we'd end up with literals of type [NSObject : AnyObject].

The new defaulting rule says that the element type of an array literal
and the key/value types of a dictionary literal can be defaulted if no
stronger type can be inferred. The default type is:

  Any, for the element type of an array literal or the value type of a
  dictionary literal, or

  AnyHashable, for the key type of a dictionary literal.

The latter is intended to compose with implicit conversions to
AnyHashable, so the most-general inferred dictionary type is
[AnyHashable : Any] and will work for any plausible dictionary
literal.

To prevent this inference from diluting types too greatly, we don't
allow this inference in "top-level" expressions, e.g.,

  let d = ["a" : 1, "b" : "two"]

will produce an error because it's a heterogeneous dictionary literal
at the top level. One should annotate this with, e.g.,

  let d = ["a" : 1, "b" : "two"] as [String : Any]

However, we do permit heterogeneous collections in nested positions,
to support cases like the original motivating example.

Fixes rdar://problem/27661580.
2016-08-04 20:58:13 -07:00
Harlan Haskins
a99ca851df Add empty parens to var-to-function renames 2016-08-04 11:03:36 -07:00
Rintaro Ishizaki
2f6b6d2c67 [Fix-it] Support defaulted and variadic arguments in renamed fix-it 2016-08-05 02:05:42 +09: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
John McCall
29ccaafc81 Merge pull request #3882 from apple/WIP-SE-0117
Implement SE-0117 (DON'T MERGE)
2016-08-02 08:56:02 -07:00
Chris Lattner
300462ea45 fix <rdar://problem/27650521> Fixits for escaping closure parameters are inserted into wrong location 2016-08-02 08:48:57 -07:00