Commit Graph

86 Commits

Author SHA1 Message Date
Doug Gregor
b3790978d1 [Type checker] Fix assertion diagnosting a rename with a different # of arguments. 2019-09-10 10:33:03 -07:00
Alexis Laferrière
abbbc01d20 Allow the use of unavailable types from unavailable code
This change permits the use of unavailable types in unavailable signatures.
It affects only usage of `available(*, unavailable)`.

This fixes a compilation error in swift-corelibs-foundation/Foundation/
URLSession/URLSessionConfiguration.swift where an unavailable property
was typed by an unavailable type.
2019-07-03 11:40:22 -07:00
mishal_shah
1e38fc3030 Update master to build with Xcode 11 beta, macOS 10.15, iOS 13, tvOS 13, and watchOS 6 SDKs 2019-06-03 22:50:02 -07:00
Karoy Lorentey
1069fc2c44 Revert "Support unavailable and obsoleted attributes on extensions" (#25127) 2019-05-29 15:16:49 -07:00
Alexis Laferrière
9b59ec54b2 Allow the use of unavailable types from unavailable code
This change permits the use of unavailable types in unavailable signatures.
It affects only usage of `available(*, unavailable)`.

This fixes a compilation error in swift-corelibs-foundation/Foundation/
URLSession/URLSessionConfiguration.swift where an unavailable property
was typed by an unavailable type.
2019-05-24 10:22:38 -07:00
Brent Royal-Gordon
facaad1873 A diagnosis from the argument clinic (#20997)
[Parse] Warn if the same argument is specified more than once in @available
2018-12-04 01:05:09 -08:00
Pavel Yaskevich
63b802ca88 [AST/Printing] Don't omit empty labels in special names
This makes diagnostics more verbose and accurate, because
it's possible to distinguish how many parameters there are
based on the message itself.

Also there are multiple diagnostic messages in a format of
`<descriptive-kind> <decl-name> ...` that get printed as
e.g. `subscript 'subscript'` if empty labels are omitted.
2018-09-24 18:36:53 -07:00
fischertony
9a05c9edf9 Add test for usage of deprecated inherited init 2018-09-13 14:59:18 +03:00
fischertony
f5e363df00 [Sema] Suppress deprecation warnings in synthesized code 2018-09-12 15:19:34 +03:00
Jordan Rose
23260b8e7b Revert "'@available' without an OS is ignored on extensions" warning (#16298)
This is still useful for the feature where deprecated declarations are
allowed to be used within a context that's marked deprecated. There's
probably a better balance to be found here, because marking the
extension deprecated still does not mark all the members deprecated,
but for now it still has an effect, and we shouldn't produce a warning
for legitimately making use of that effect.

The warning was added in f21d9f332, mostly as an opportunity "fix".

https://bugs.swift.org/browse/SR-7577
2018-05-02 16:53:24 -07:00
Jordan Rose
0b632aa9df Diagnose unavailable getters and setters
This handles the case where one accessor is /unavailable/ but not the
other. This is rarer than deprecation (handled in b0e12f4c), but could
still happen.

Finishes rdar://problem/18633725 / SR-7201.
2018-04-10 19:35:43 -07:00
Slava Pestov
f7697291df Parse: Backward compatibility for old spellings @_inlineable and @_versioned
Just parse these as @inlinable and @versioned, then emit a warning
(Swift 4.2 and below) or error (Swift 5).
2018-03-30 21:55:31 -07:00
Jordan Rose
b0e12f4c80 Check deprecation for getters and setters
This handles the case where just one accessor is deprecated but not
the other, which does come up sometimes in Apple's frameworks.

rdar://problem/18633725
2018-03-16 10:12:52 -07:00
Jordan Rose
f21d9f332d Allow @available(swift, ...) nested within @available(macOS, ...)
Previously, we treated this as an attempt to widen the availability
of a member beyond its context, but it's really a different axis of
availability.

Also, warn about using @available on extensions without an OS, which
we just completely ignore right now.

rdar://problem/32632327
2018-03-14 16:37:36 -07:00
Max Moiseev
4c0368a02a [test] Cleaning up tests 2017-08-29 10:04:39 -07:00
Pavel Yaskevich
e5a2c7c7dc [QoI] Improve fix-it when renamed method has contextual member lookup argument
Currently we generate incorrect fix-it in situations where we
have contextual member lookup as one of the arguments.

Resolves: rdar://problem/32526620
2017-07-14 12:15:29 -07:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Michael Ilseman
045bc16b6d Merge pull request #4031 from milseman/noescape_by_default
noescape by default: deprecate @noescape and @autoclosure(escaping)
2016-08-05 13:25:00 -07:00
Michael Ilseman
caa9d67469 [noescape by default] Emit deprecation warning/fixit for @noescape
@noescape is now the default behavior, so deprecate it and offer a
fixit.
2016-08-04 16:28:43 -07:00
Rintaro Ishizaki
2f6b6d2c67 [Fix-it] Support defaulted and variadic arguments in renamed fix-it 2016-08-05 02:05:42 +09:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07:00
Michael Ilseman
c37751ae96 [noescape by defaul] make noescape the default
This flips the switch to have @noescape be the default semantics for
function types in argument positions, for everything except property
setters. Property setters are naturally escaping, so they keep their
escaping-by-default behavior.

Adds contentual printing, and updates the test cases.

There is some further (non-source-breaking) work to be done for
SE-0103:

- We need the withoutActuallyEscaping function
- Improve diagnostics and QoI to at least @noescape's standards
- Deprecate / drop @noescape, right now we allow it
- Update internal code completion printing to be contextual
- Add more tests to explore tricky corner cases
- Small regressions in fixits in attr/attr_availability.swift
2016-07-29 13:49:08 -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
Tony Parker
2a4e916296 Rename OutputStream to TextOutputStream [SE-0086] 2016-07-18 16:47:23 -07:00
Robert Widmann
2bcb86264b Do not subject protocol Self to accessibility diagnostics
It is currently impossible to declare a protocol as unavailable and
still ship valid Swift code because while typechecking protocol Self,
we attempt to do an accessibility check on its generic signature and
find that, surprise surprise, the protocol is unavailable.  Rather than
plumb another parameter through Sema, this patch piggybacks on existing
behavior of AllowPotentiallyUnavailableProtocol to disable the check
for protocol self.
2016-07-12 02:51:57 -07:00
Xi Ge
1e85e1bcd2 Revert "[Fixit] Add a fixit for converting non-trailing closures to trailing closures (#3317)"
This patch needs some polish to fix more false positives found by @rintaro and @lattner
2016-07-02 09:39:07 -07:00
Xi Ge
1886b4ab56 [Fixit] Add a fixit for converting non-trailing closures to trailing closures (#3317)
* [Fixit] Add a fixit for converting non-trailing closures to trailing closures.

* [test] Update test to reflect the added note about converting to trailing closures.
2016-07-02 08:11:58 -07:00
Rintaro Ishizaki
ba2e4e144f [Fix-it] In fixItAvailableAttrRename, handle the case args is TupleShuffleExpr (#3040)
Also, handle the ParenExpr is trailing closure case.

Fix-it used to add `fn: ` label before trailing closure:

   // (tuple_shuffle_expr (paren_expr trailing-closure)) case:
   @available(*, unavailable, renamed: "bar(fn:)")
   func foo(closure: () -> Int) {}
   foo { 0 }

   // (paren_expr trailing-closure) case:
   @available(*, unavailable, renamed: "bar(fn:)")
   func foo(_: () -> Int) {}
   foo { 0 }

   // (tuple_shuffle_expr (tuple_expr trailing-closure)) case:
   @available(*, unavailable, renamed: "bar(x:fn:)")
   func oldFunc6(_ x: Int, y: @noescape () -> Int) { }
   foo(0) { 1 }
2016-07-01 12:58:34 +09:00
Jordan Rose
7c998776ff Update the "'=' to ':' in attributes" fix-it to include a space.
...because it was bugging me, and because the migrator uses it.
2016-06-09 11:30:58 -07:00
Jordan Rose
3d9d0a3c90 Allow nested names in @available(*, renamed:"..."). (#2722)
This can be used as QoI for things like 'NSASCIIStringEncoding', which
is going to canonically be `String.Encoding.ascii` if/when SE-0086 is
accepted.

We can't actually handle this in NS_SWIFT_NAME (that is, we can't
/import/ something onto a nested type), but that's okay: we already
have stricter limitations on NS_SWIFT_NAME enforced by Clang.

rdar://problem/26352374
2016-05-26 12:54:05 -07:00
Slava Pestov
19f72c8593 ClangImporter: Fix diagnostics for NS* prefix stripping from generic types
We were failing to create an unavailable TypeAlias for the old name
in the case the renamed type was generic, leading to poor diagnostics.

Also, Sema resolves generic TypeAliases very early, while building
a Type from a TypeRepr -- this means the unavailable/deprecated
check runs too late to catch generic TypeAlises.

Add a hack where we preserve a reference to the original TypeAliasDecl
by way of constructing a SubstitutedType which desugars to the
replacement type, rather than resolving the replacement type
directly, so that the availability check can pick it up.

A better fix for this would be to introduce a BoundGenericAliasType
sugared type, but that's a bigger change that can come later.

Fixes <rdar://problem/26206263>.
2016-05-25 00:32:11 -07:00
Jordan Rose
5343b594de Don't try to apply fix-its for renamed operators.
...or renaming to operators, unless we're sure the original thing was
an operator expression. There are just a lot of ways this can be
screwed up.

(Some cases of this can certainly be implemented. I may file a
StarterBug later.)
2016-05-20 16:58:50 -07:00
Jordan Rose
ced32f5714 Fix renaming fix-it when trailing closures are present.
Not crashing isn't good enough; we need to actually replace the
right text!

rdar://problem/26305887
2016-05-20 16:58:50 -07:00
Trent Nadeau
0cc851568a Updated tests to use @discardableResult and _ = . 2016-05-11 22:53:38 -04:00
Jordan Rose
f952d2ee3a Provide fix-its when overriding something that's been renamed.
This is the second half of the previous commit. The most common case
of this will be due to the new rules for imported Objective-C API,
but it will also catch things like "I forgot to make the first
parameter not have an argument label".
2016-05-09 16:02:35 -07:00
Jordan Rose
e67fe08a26 Improve message when trying to override an unavailable member. 2016-05-09 16:02:35 -07:00
Jordan Rose
e09be3bdc9 Continue improving initializers in @available(renamed:).
Refinement of d858cc96. Handle members renamed to initializers as well
as free functions renamed to initializers.
2016-05-06 14:56:19 -07:00
Jordan Rose
d858cc96c7 Improve handling of initializers in @available(renamed:).
If we know the renamed thing is being called, we can just use
"Foo(...)" in the resulting expression (rather than "Foo.init(...)").
2016-05-06 13:22:58 -07:00
Jordan Rose
2fa1626579 Improve diagnostic text for @available(renamed:).
We don't want to show the funny "getter:Foo.bar(self:)" syntax to
developers, so whenever possible be a little more explicit.

    'foo' has been replaced by 'X.newFoo'
    'bar(x:)' has been replaced by property 'X.bar'
    'baz(x:y:)' has been replaced by instance method 'X.baz(y:)'

(We do run up against the limitation of a string -- this diagnostic
does not do any lookup to find out if the resulting decl actually exists.)
2016-05-05 18:07:39 -07:00
Jordan Rose
2c25d85cdf Handle "setter:" in @available(renamed:).
Example:

    @available(*, unavailable, renamed: "setter:CGRect.diagonal(self:_:)")
    func scale(_ rect: inout CGRect, toDiagonalLength length: CGFloat)

(My examples are getting more and more contrived, but there you go.)

This is pretty much the same as the getter handling, except that we also
want to strip off the '&' at the call site.
2016-05-05 14:46:34 -07:00
Jordan Rose
52caa75c11 Fix fix-it ranges for instance method @available(renamed:).
While I'm at it, prefer deleting trailing commas and space to leading
commas and space when removing an argument. That's a little more
aesthetically pleasing. We still have to delete a preceding comma if
it's the last argument that's being removed.
2016-05-05 14:46:34 -07:00
Jordan Rose
272e938876 Handle "getter:" in @available(renamed:).
Example:

    @available(*, unavailable, renamed: "getter:UIColor.CIColor(self:)")
    func convertToCIColor(_ color: UIColor) -> CIColor

This syntax looks weird, but it's the same as what's used by
NS_SWIFT_NAME. I intend to improve the diagnostic text once I have
all the fix-its working.

Next up: setters!
2016-05-05 14:46:34 -07:00
Jordan Rose
894318cfe0 Allow instance member syntax in @available(renamed:).
Example:

    @available(*, unavailable, renamed: "Sequence.enumerated(self:)")
    func enumerate<Seq: SequenceType>(_ sequence: Seq) ->
        EnumerateSequence<Seq>

This will allow us to reuse this logic to suggest fixes for APIs
turned into members by NS_SWIFT_NAME.
2016-05-04 14:17:15 -07:00
Jordan Rose
2966d99dbb Fix a use-after-delete in ec59bf9f caught by ASan. 2016-04-29 10:33:01 -07:00
Jordan Rose
797260939e Handle argument labels in @available(renamed:"...")
Fixes SR-1008 / rdar://problem/25276961
2016-04-28 20:21:30 -07:00
Jordan Rose
d7b3b6a462 Validate the "renamed" argument to @available.
It should have the same form as the argument to NS_SWIFT_NAME
in Objective-C, except that it permits operators and (currently)
disallows instance members and properties. We do get to share the
same parsing code, at least.

This actually caught an error in the Foundation overlay!

Groundwork for SR-1008.
2016-04-28 20:21:30 -07:00
Chris Lattner
183ae24249 Upgrade deprecation warnings about snake case identifiers, C style for loops,
and : vs = in attributes to errors.
2016-04-17 10:20:12 -07:00
Daniel Duan
7cabf3555b [Parser] update test for SE-0040 changes 2016-03-11 16:01:37 -08:00
Max Moiseev
7fe6916bf6 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-07 12:10:47 -08:00
Kevin Yu
8f193c856e [gardening] Fix typos "cant" -> "can't", "dont" -> "don't" 2016-03-06 00:25:14 +00:00