Commit Graph

109 Commits

Author SHA1 Message Date
Slava Pestov
2ef101c815 Sema: Don't add local functions to TC.definedFunctions
Instead, check them and their error handling right away.

In addition to fixing the crash in the radar, this also causes
us to emit unused variable warnings in functions containing
local functions.

Eventually, TC.definedFunctions should go away altogether.

Fixes <rdar://problem/53956342>.
2019-08-07 00:37:21 -04:00
Brent Royal-Gordon
3494c0bd88 [TypeChecker] Rephrase platforms in availability diagnostics
This does several different things to improve how platforms are described in availability diagnostics:

• Mentions the platform in diagnostics for platform-specific @available(unavailable) attributes.
• Replaces “OS X” with “macOS”.
• Replaces “fooOS application extension” with “application extensions for fooOS”.
• Replaces “on fooOS” with “in fooOS”.

Fixes <rdar://problem/49963341>.
2019-04-30 16:32:43 -07:00
Nate Chandler
c21678d34a Corrected tests by removing implicit returns. 2019-04-24 10:04:20 -07: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
Slava Pestov
463a467046 Merge pull request #18026 from slavapestov/inherited-availability-attribute-part-2
Sema: Fix availability of inherited designated initializers, part 2
2018-07-30 18:40:11 -07:00
Jordan Rose
6290d9be60 Introduce DescriptiveDeclKind::Property (#18183)
...and collapse StaticVar/ClassVar and StaticLet/ClassLet into
StaticProperty/ClassProperty.

"var" and "let" aren't great nouns to use in diagnostics to begin with,
especially alongside semantic terms like "instance method". Focus on
the type vs. non-type aspect instead with "property", which better
matches how people talk about member vars (and lets) anyway.
2018-07-30 09:23:59 -07:00
Slava Pestov
336f51e5bc Sema: Fix availability of inherited designated initializers, part 2
We need to explicitly handle nested types here.

Fixes the (re-opened) <rdar://problem/40853731>,
<https://bugs.swift.org/browse/SR-7881>.
2018-07-24 16:13:45 -07:00
Slava Pestov
cc06543e87 Sema: Remove third pass over parameter list when validating generic functions and subscripts
The code for performing the third pass using the GenericToArchetypeResolver
is still there, but it only runs for non-generic declarations.

The next step is to consolidate this path with the generic path.
2018-07-18 01:54:24 -07:00
Slava Pestov
ae6c75ab5d Sema: Fix availability of inherited designated initializers
Inherited designated initializers got the same availability
as the corresponding initialier in the superclass.

However if the superclass was more available than the subclass,
we would generate a diagnostic that a member cannot be more
available than its containing type.

This diagnostic had an unknown source location, since the
location was for a synthesized declaration, causing confusion.

Fixes <https://bugs.swift.org/browse/SR-7881> aka
<rdar://problem/40853731>.
2018-06-08 23:23:43 -07:00
Jordan Rose
6bd7e5e5b4 Make sure protocol witness errors don't leave the conformance context
That is, if there's a problem with a witness, and the witness comes
from a different extension from the conformance (or the original type,
when the conformance is on an extension), put the main diagnostic on
the conformance, with a note on the witness. This involves some
shuffling and rephrasing of existing diagnostics too.

There's a few reasons for this change:

- More context. It may not be obvious why a declaration in file
  A.swift needs to be marked 'public' if you can't see the conformance
  in B.swift.

- Better locations for imported declarations. If you're checking a
  conformance in a source file but the witness came from an imported
  module, it's better to put the diagnostic on the part you have
  control over. (This is especially true in Xcode, which can't display
  diagnostics on imported declarations in the source editor.)

- Plays better with batch mode. Without this change, you can have
  diagnostics being reported in file A.swift that are tied to a
  conformance declared in file B.swift. Of course the contents of
  A.swift also affect the diagnostic, but compiling A.swift on its
  own wouldn't produce the diagnostic, and so putting it there is
  problematic.

The change does in some cases make for a worse user experience,
though; if you just want to apply the changes and move on, the main
diagnostic isn't in the "right place". It's the note that has the info
and possible fix-it. It's also a slightly more complicated
implementation.
2018-05-10 19:31:12 -07:00
Doug Gregor
58356f9bf5 Update test case now that we produce fewer redundant diagnostics. 2017-09-24 23:08:17 -07:00
Joe Shajrawi
00f44ce24a Revert "Create fewer generic signature builders" 2017-09-22 21:57:53 -07:00
Doug Gregor
a9873b4d15 Update test case now that we produce fewer redundant diagnostics. 2017-09-22 12:37:49 -07:00
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
Paweł Szot
e935700c25 [SR-4087] fix "add @available attribute" location (#7864) 2017-03-03 10:51:02 -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
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
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
David Farler
7bfaeb57f1 [SE-0081] Warn on deprecated where clause inside angle brackets
and provide a fix-it to move it to the new location as referenced
in SE-0081.

Fix up a few stray places in the standard library that is still using
the old syntax.

Update any ./test files that aren't expecting the new warning/fix-it
in -verify mode.

While investigating what I thought was a new crash due to this new
diagnostic, I discovered two sources of quite a few compiler crashers
related to unterminated generic parameter lists, where the right
angle bracket source location was getting unconditionally set to
the current token, even though it wasn't actually a '>'.
2016-07-26 01:41:10 -07:00
Slava Pestov
ddc51c5917 AST: Implement SE-0102, introducing new semantics for Never alongside @noreturn
No migrator support yet, and the code for @noreturn is still in
place.
2016-07-22 14:56:39 -07:00
Devin Coughlin
c553de4478 [Sema] Remove 'deployment target ensures guard will always be true'
Remove the diagnostic that warns when an availability check is unnecessary
because the minimum deployment target ensures it will always be true. This
diagnostic is valuable (it tells users that they have dead fallback code) but
can also be super annoying when a source file is shared between projects with
different deployment targets. There is not currently a good mechanism to
suppress these warnings (for example, by expressing a "compatibility version" in
the source or as a build setting) and so it is better to turn the diagnostic
off.

rdar://problem/22337402
2016-07-10 19:00:47 -04:00
Chris Lattner
3549ec5404 [QoI] make several improvements to the unused expression diagnostics, to go
along with recent policy changes:

- For expression types that are not specifically handled, make sure to
  produce a general "unused value" warning, catching a bunch of unused
  values in the testsuite.

- For unused operator results, diagnose them as uses of the operator
  instead of "calls".

- For calls, mutter the type of the result for greater specificity.

- For initializers, mutter the type of the initialized value.

- Look through OpenExistentialExpr's so we can handle protocol member
  references propertly.

- Look through several other expressions so we handle @discardableResult
  better.
2016-05-16 23:26:07 -07:00
Trent Nadeau
0cc851568a Updated tests to use @discardableResult and _ = . 2016-05-11 22:53:38 -04:00
Chris Lattner
8746676616 Move @noescape and @autoclosure to their new places in various tests, NFC. 2016-04-15 16:05:35 -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
Daniel Duan
7cabf3555b [Parser] update test for SE-0040 changes 2016-03-11 16:01:37 -08:00
Ben Langmuir
ceb1069199 Prefer original spelling of 'static' vs. 'class'
Try to match the original spelling of static/class in diagnostics and
when printing the AST. Also fixes cases with
PrintOptions.PrintImplicitAttrs = false, where we would just print
'class', which was not valid code.
2016-03-03 13:48:30 -08:00
Chris Lattner
dfaaebc0a0 Merge pull request #1333 from dduan/SE-0031
[SE-0031] Adjusting 'inout' Declarations for Type Decoration
2016-02-26 10:41:58 -08:00
Daniel Duan
780b58a9a5 [Parser] update tests for 'inout' syntax adjustment 2016-02-26 01:33:22 -08:00
practicalswift
ce6afbbc2d [gardening] Fix recently introduced typo: "createable" → "creatable" 2016-02-24 07:35:42 +01:00
Doug Gregor
38c1de69e4 Reinstate "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit ce7b2bcf09, tweaking
a few validation tests appropriately (1 crasher fixed, two -verify
tests that needed updating).
2016-01-14 00:21:48 -08:00
Erik Eckstein
ce7b2bcf09 Revert "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit 2b2e9dc80e.

It broke some compiler crasher tests
2016-01-13 20:42:58 -08:00
Slava Pestov
79b24fa7d1 Update availability tests to be independent of the actual deployment target
Use fictional version numbers in the 10.50..10.99 range.
2016-01-13 19:27:26 -08:00
gregomni
2b2e9dc80e [SR-511][Parse] Add 'associatedtype' keyword and fixit
Adds an associatedtype keyword to the parser tokens, and accepts either
typealias or associatedtype to create an AssociatedTypeDecl, warning
that the former is deprecated. The ASTPrinter now emits associatedtype
for AssociatedTypeDecls.

Separated AssociatedType from TypeAlias as two different kinds of
CodeCompletionDeclKinds. This part probably doesn’t turn out to be
absolutely necessary currently, but it is nice cleanup from formerly
specifically glomming the two together.

And then many, many changes to tests. The actual new tests for the fixits
is at the end of Generics/associated_types.swift.
2016-01-13 17:54:31 -08:00
Ge Sen
7ac02d54ba Erase redundant whitespaces. 2015-12-10 13:35:06 +08:00
Joe Groff
fbd2e4d872 Rename @asmname to @_silgen_name.
This reflects the fact that the attribute's only for compiler-internal use, and isn't really equivalent to C's asm attribute, since it doesn't change the calling convention to be C-compatible.
2015-11-17 14:13:48 -08:00
Devin Coughlin
1165aca545 [Sema] Suppress deprecation/availability diagnostics in branches with empty availability
We currently emit diagnostics for references to deprecated and potentially
unavailable APIs in branches that are dead for the current platform and
minimum deployment target. These dead branches can arise when sharing swift
source between targets or in playgrounds intended to be run on multiple OS
versions.

So for example, suppose the developer has the following code targeting
OSX 10.9+ and iOS 8.0+:

if #available(OSX 10.10, *) {
  // Use replacement API introduced in OSX 10.10/iOS 8.0
} else {
  // Use old API deprecated in OSX 10.10/iOS 8.0
}

Compiling the above for iOS and with a miniminum deployment of 8.0 will
result in a deprecation diagnostic for the use of the API in the else branch
even though that branch will never execute. (Note that the branch is not dead on
the OSX target because the minimum deployment target is 10.9. For OSX we also
won't emit a deprecation warning because the API wasn't deprecated until 10.10.

This commit updates availability checking to create refinement contexts with
empty OS version ranges for #available() else branches when those branches
will definitely not execute. It suppresses deprecation and potential
availability diagnostics within those contexts. It does not suppress diagnostics
for references to APIs annotated as unconditionally unavailable (i.e., with
@available(OSX, unavailable, ...) and friends).

rdar://problem/22307360

Swift SVN r31631
2015-09-02 18:18:30 +00:00
Chris Lattner
649e5f937d generalize the existing ? and + constraints on expected diagnostics to
a simpler and more general * constraint.  This paves the way for other improvements.



Swift SVN r30622
2015-07-25 05:23:30 +00:00
Devin Coughlin
3944a1620d Sema: Update diagnostic text for when @available cannot be applied to a variable.
This changes the diagnostic text when a variable cannot be marked potentially unavailable
so that it does not explicitly use the long-style form of @available:

It changes:
  "stored properties cannot be marked potentially unavailable with 'introduced='"
to:
  "stored properties cannot be marked potentially unavailable with '@available'"

Swift SVN r30446
2015-07-21 16:33:51 +00:00
Devin Coughlin
be17941059 Sema: Build type refinement contexts for functions without bodies.
We were skipping building refinement contexts for function declarations without bodies
(such as protocol requirements and @asmname functions). These contexts are needed to
determine whether parameter and return types are available in those declaration.

Swift SVN r30380
2015-07-19 02:09:17 +00:00
Devin Coughlin
78c1961195 Sema: Add Fix-It suggesting @available() to lazy properties
It is safe to add an @available attribute to lazy properties, so suggest a
Fix-It to do so if the property references a potentially unavailable symbol.

rdar://problem/20968204

Swift SVN r30321
2015-07-17 19:01:14 +00:00
Devin Coughlin
538df11695 Sema: Update availability diagnostic for accessor override to mention accessor kind
Update the diagnostic emitted when an accessor override is less available than the
declaration it overrides to mention the accessor kind and the name of the property rather
than just the accessor declaration name, which is '_'.

rdar://problem/20427938

Swift SVN r30319
2015-07-17 17:17:00 +00:00
Devin Coughlin
217d17d6e6 Sema: Consider availability of protocol declaration when diagnosing protocol witness availability.
Now that we allow types to conform to protocols that are less available than the
type itself, we should consider the availability of the protocol when
determining whether a witness is sufficiently available to satisfy the protocol
requirement.

In particular, we should allow the following:

@available(iOS 9.0, *)
class UIRefrigerator { }

@available(iOS 9.0, *)
protocol UIRefrigeratorDelegate {
  func refrigeratorDidCool(refrigerator: UIRefrigerator)
}

@available(iOS 7.0, *)
class MyViewController : UIViewController, UIRefrigeratorDelegate {
  @available(iOS 9.0, *)
  func refrigeratorDidCool(refrigerator: UIRefrigerator) {
    ...
  }
}

This is safe because MyViewController's refrigeratorDidCool() witness is
available everywhere the protocol is available. To check this, we now
additionally intersect the availability of the protocol with the availabilities
of the witness and the requirement before checking containment.

Swift SVN r29996
2015-07-08 22:43:27 +00:00
Devin Coughlin
f93515fa8d Sema: Allow types to conform to protocols that are less available than the type itself.
The previous rules for availability checking prevented types from conforming to protocols
that were less available than the type itself. This was too restrictive, because we want
to allow developers to add additional behavior to their existing classes to
conform to new protocols while still employing older functionality from those classes on
older OSes:

@available(iOS 9.0, *)
protocol UIRefrigeratorDelegate { }

@available(iOS 8.0, *)
class MyViewController : UIViewController, UIRefrigeratorDelegate { }

We now support this idiom (and adding conformnces via protocol extensions) by allowing
references to potentially unavailable protocols inside inheritance clauses.

It is still an availability error to refer to potentially unavailable protocols in other
settings -- so, for example, attempting to cast to an unavailable protocol will cause
a compile-time error.

rdar://problem/21718497

Swift SVN r29958
2015-07-08 04:22:14 +00:00
Devin Coughlin
550b9feb05 [Sema] Improve clarity of fix-it hint to add #available.
As suggested by Jordan, change "add if #available version check" to
"add 'if #available' version check" to make it easier to read.

Swift SVN r29650
2015-06-25 01:03:50 +00:00
Devin Coughlin
5a71aaef6c [Sema] Update availability fix-it to be consistent.
Change the fix-it suggesting adding #available to be consistent with the fix-it
adding @available.

This changes "guard with version check" to "add if #available version check".

rdar://problem/21275857

Swift SVN r29648
2015-06-25 00:23:02 +00:00
Devin Coughlin
8e071b1148 Revert "[Sema] Suppress warning about useless availability checks in playgrounds and script mode."
As Jordan notes, this uses the wrong check: isScriptMode() is also true for
main.swift in an app or command-line tool.

This reverts commit 8a72f4357bc04a386cf82acd1de06896515ab5a8.

Swift SVN r29583
2015-06-23 23:39:44 +00:00
Devin Coughlin
200b55be70 [Sema] Suppress warning about useless availability checks in playgrounds and script mode.
We normally report a warning when a #available() check will always be true
because of the minimum deployment target. These warnings are potentially
annoying when the developer either cannot change the minimum deployment target
from the default (as in playgrounds) or when doing so is burdensome (as for
command-line scripts, which would require passing a target triple) -- so
suppress them.

rdar://problem/21324005

Swift SVN r29582
2015-06-23 23:31:12 +00:00
Slava Pestov
67a1f24d59 Sema: 'dynamic' attribute now diagnoses if Foundation is not imported
This prevents us from seeing a less useful error message from SILGen
further down the line.

Also fix a bug where @objc without importing Foundation was not diagnosed
after the first top-level form. Some tests were relying on this behavior,
so fix those tests, either by splitting off the objc parts of the test, or
just by passing the -disable-objc-attr-requires-foundation-module flag.

Fixes <rdar://problem/20660270>.

Swift SVN r29359
2015-06-10 01:18:27 +00:00