Commit Graph

27 Commits

Author SHA1 Message Date
Robert Widmann
39494b2ba2 Rearrange test code for exhaustiveness 2017-04-28 02:06:39 -04:00
Doug Gregor
7dd1c87dd3 [SE-0160] Warn about uses of @objc declarations that used deprecated @objc inference.
When in Swift 3 compatibility mode without
`-warn-swift3-objc-inference`, warn on the *uses* of declarations that
depend on the Objective-C runtime that became `@objc` due to the
deprecated inference rule. This far more directly captures important
uses of the deprecated Objective-C entrypoints. We diagnose:

* `#selector` expressions that refer to one of these `@objc` members
* `#keyPath` expressions that refer to one of these `@objc` members
* Dynamic lookup (i.e., member access via `AnyObject`) that refers to
  one of these `@objc` members.
2017-03-31 21:22:15 -07:00
Rintaro Ishizaki
590ac72316 [Parse] Parse subscript with '#' expressions
Fixes: https://bugs.swift.org/browse/SR-3439
2017-01-27 19:59:55 +09:00
Slava Pestov
fbdecebf77 AST: Restore unqualified lookup quirk for Swift 3 mode
In Swift 3, unqualified lookup would skip static methods
when performing a lookup from instance context.

In Swift 4 mode, if a module method is shadowed by a static
method, you will need to qualify the module method with the
module name.

It would have been nice to isolate the quirk in Sema and
not AST, but unfortunately UnqualifiedLookup only proceeds
to lookup in the module if scope-based lookup failed to find
anything, and I don't want to change that since it risks
introducing performance regressions.

Fixes <rdar://problem/29961715>.
2017-01-12 22:43:23 -08: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
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
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Slava Pestov
3ebd53d03c AST: Name lookup shouldn't filter out static/instance methods from instance/static context
We do this in a more general way higher up in the constraint
solver. Filtering out methods in name lookup only hurts
diagnostics.

In fact I don't think this behavior was intentional at all,
since the code in question was originally written in 2013
before a lot of the more recent member lookup and diagnostic
code was added.

This does break source compatibility though, but in a minor
way. See the change to the CoreGraphics overlay. Again,
though, I think this was an accident and not intentional.
2016-08-05 14:27:16 -07:00
Robert Widmann
4f465224ea Polish off uses of dynamicType in tests 2016-07-29 16:59:14 -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
Alex Hoppen
884af9ccab [Parser] Make #selector a primary expression
This allows #selector to be followed by a trailing `?` in case statements as reported in SR-1827
2016-06-27 22:11:58 +02:00
Rintaro Ishizaki
1bdce7ced6 [lit] Add substitutions: %utils and %line-directive
%utils => ${SWIFT_SOURCE_DIR}/utils
%line-directive => ${SWIFT_SOURCE_DIR}/utils/line-directive
2016-06-11 02:41:15 +09:00
John McCall
3fc2291733 Add basic typo correction for unqualified lookup.
There's a lot of room for better QoI / performance here.
2016-05-20 11:04:58 -07:00
practicalswift
21c872c590 [gardening] Fix recently introduced typos. 2016-05-14 20:33:28 +02:00
Doug Gregor
3650ce8ecd SE-0064 / SR-1239: Fix-Its for string-literal selectors naming property accessors.
When we see a string literal used to initializer a Selector, and that
string literal names the selector for the getter or setter of an
Objective-C property, suggest #selector(getter: ...) or

This completes SE-0064. Big thanks for Alex Hoppen (@ahoppen) for his
contributions here.
2016-05-11 23:03:37 -07:00
Alex Hoppen
d2e045c8b5 Implement SE-0064 / SR-1239: #selector for property getters and setters
Implements the core functionality of SE-0064 / SR-1239, which
introduces support for accessing the Objective-C selectors of the
getter and setter of an @objc property via #selector(getter:
propertyName) and #selector(setter: propertyName).

Introduce a bunch of QoI around mistakes using #selector to refer to a
property without the "getter:" or "setter:", using Fix-Its to help the
user get it right. There is more to do in this area, still, but we
have an end-to-end feature working.

Much of the implementation and nearly all of the test cases are from
Alex Hoppen (@ahoppen). I've done a bit of refactoring, simplified the
AST representation, and replaced Alex's custom
expression-to-declaration logic with an extension to the constraint
solver. The last bit might be short-lived, based on swift-evolution
PR280, which narrows the syntax of #selector considerably.
2016-05-11 16:51:27 -07:00
Chris Lattner
14c7a3dafe implement SE-0071 - Allow (most) keywords in member references 2016-05-02 22:31:14 -07:00
Josef Willsher
de18967992 [Sema] Improved error message for static functions on existential metatypes (#2127)
Type level lookups can fail because the lookup is on an existential
metatype, like `MyProtocol.staticMethod(_:)` is invalid; however the
error message is unclear: “static member 'staticMethod(_:)' cannot be
used on instance of type ‘MyProtocol.Protocol’”.

This fix checks the base of member lookups that failed with the reason
UR_TypeMemberOnInstance for being existential metatypes. It produces
the clearer message “static member ‘staticMethod(_:)’ cannot be used on
protocol metatype ‘MyProtocol.Protocol’”. This change makes it clear
that the use of a static member on the *existential* metatype is the
problem.
2016-04-10 19:03:20 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
PiersonBro
38f7f5f203 [Sema] Add "unused result" warning for #selector.
Fixes https://bugs.swift.org/browse/SR-1022.
2016-04-03 18:22:10 -07:00
Doug Gregor
6cbffa7c2a [Sema] Make it possible to suppress warnings about Selector("foo").
When the selector named by Selector("foo") does not map to a known
Objective-C method, allow one to suppress the warning by wrapping the
string literal in an extra set of parentheses, e.g.,

  Selector(("foo"))

Suggest this via a Fix-It on a note so it's discoverable. Addresses
rdar://problem/24791200.
2016-03-21 17:02:40 -07:00
Kevin Ballard
59df50960e [Sema] Improve diagnostics for #selector() expressions
When the `#selector()` expression refers to a parameter or variable, we
don't want to call it a property.

Fixes the rest of SR-880.
2016-03-05 00:31:11 -08:00
Kevin Ballard
502b159400 [Parse] Store DeclNames in Scope instead of Identifiers
This fixes a problem where compound names like `foo(_:bar:)` were being
resolved to variables declared with the same base name.

Fixes most of SR-880.
2016-03-04 23:42:17 -08:00
Doug Gregor
9a0241bb3b SE-0022: Address Jordan's review comments about #selector. 2016-01-28 12:09:57 -08:00
Doug Gregor
1a830fa541 SE-0022: Deprecate string-literal-as-selector in favor of #selector.
Introduce Fix-Its to aid migration from selectors spelled as string
literals ("foo:bar:", which is deprecated), as well as from
construction of Selector instances from string literals
(Selector("foo:bar"), which is still acceptable but not recommended),
to the #selector syntax. Jump through some hoops to disambiguate
method references if there are overloads:

    fixits.swift:51:7: warning: use of string literal for Objective-C
         selectors is deprecated; use '#selector' instead
      _ = "overloadedWithInt:" as Selector
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          #selector(Bar.overloaded(_:) as (Bar) -> (Int) -> ())

In the cases where we cannot provide a Fix-It to a #selector
expression, we wrap the string literal in a Selector(...) construction
to suppress the deprecation warning. These are also easily searchable
in the code base.

This also means we're doing more validation of the string literals
that go into Selector, i.e., that they are well-formed selectors and
that we know about some method that is @objc and has that
selector. We'll warn if either is untrue.
2016-01-28 10:58:27 -08:00
Doug Gregor
dccf3155f1 SE-0022: Implement parsing, AST, and semantic analysis for #selector. 2016-01-26 21:12:04 -08:00