Commit Graph

23 Commits

Author SHA1 Message Date
Anthony Latsis
2cd90bdd69 AST: Quote attributes more consistently in DiagnosticsSema.def 2025-04-22 18:23:36 +01:00
Allan Shortlidge
0fd2f3fc1c Sema: Diagnose @_spi_available on declarations that cannot be unavailable.
The attribute makes the declaration unavailable from the perspective of clients
of the module's public interface and was creating a loophole that admitted
inappropriate unavailability.
2025-03-07 19:44:48 -08:00
Allan Shortlidge
949a6c68d7 AST/Sema: Retire SemanticAvailableAttr::getVersionAvailability().
Query for availability constraints instead of calling getVersionAvailability().
2025-02-16 07:44:45 -08:00
Allan Shortlidge
fdcf53cca6 Tests: Test conformance checker with witnesses in unavailable extensions.
A protocol conformance witness must be as available as its requirement. In
Swift 6.1 and earlier, the conformance checker failed to note that witnesses in
unavailable extensions are unavailable. That bug was fixed by a previous
change, but there was no test case covering it so the difference in behavior
was not acknowledged.

Related to rdar://143466010.
2025-01-23 21:13:24 -08:00
Allan Shortlidge
a860b02360 Sema: Diagnose unavailability of associated type decls.
It should not be possible to mark an associated type declaration unavailable
since doing so does not have an effect on how a conformance interacts with its
associated types.
2024-09-11 16:42:47 -07:00
Alex Hoppen
66104395d7 [Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
Some editors use diagnostics from SourceKit to replace build issues. This causes issues if the diagnostics from SourceKit are formatted differently than the build issues. Make sure they are rendered the same way, removing most uses of `DiagnosticsEditorMode`.

To do so, always emit the `add stubs for conformance` note (which previously was only emitted in editor mode) and remove all `; add <something>` suffixes from notes that state which requirements are missing.

rdar://129283608
2024-08-07 14:01:30 -07:00
Allan Shortlidge
5da4e2df40 Sema: Allow unavailable decls to witness requirements in more conformances.
In https://github.com/apple/swift/pull/63898 conformance requirement
typechecking was relaxed to allow unavailable decls to witness conformance
requirements as long as the conforming nominal was also unavailable. However,
only nominals that were directly marked unavailable were accepted. Nominals
that are declared in unavailable scopes should also be allowed to have
unavailable wintesses.

Resolves rdar://107052715
2023-03-22 12:37:51 -07:00
Allan Shortlidge
9521764b18 Sema: Allow unavailable protocol witnesses in unavailable nominals or extensions.
Resolves rdar://99451416
2023-02-28 13:54:35 -08:00
Rajagopalan-Gangadharan
585350d405 Add example code as test 2021-07-29 00:11:04 +05:30
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
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Doug Gregor
a6516a90c6 [Type checker] Bump warning about unavailable witnesses to an error in Swift 4
Swift 3 allowed a requirement to be satisfied by an unavailable
witness, which doesn't make sense. We've been warning about it in
Swift 3 for a while; make it an error in Swift 4.
2017-07-10 11:40:35 -07:00
Doug Gregor
9ebc4caa41 [Type checker] Warn about unavailable witnesses used to satisfy a requirement. 2017-04-27 22:40:21 -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
Jorge Bernal
0a3f913b20 SE-0070: Make Optional Requirements Objective-C-only.
Optional protocol requirements now require an explicit @objc attribute.

Fixes SR-1395
2016-05-06 11:05:52 +02:00
Ted Kremenek
62feb5c949 Change @availability to @available.
This came out of today's language review meeting.
The intent is to match #available with the attribute
that describes availability.

This is a divergence from Objective-C.

Swift SVN r28484
2015-05-12 20:06:13 +00:00
Doug Gregor
2bf69a0ea0 Require witnesses for @objc requirements to be @objc.
Previously, we attempted to infer @objc-ness based on conformance, but
doing so is fraught with ordering dependencies, and just doesn't work
in the general case. Among other crimes, this allowed us to
retroactively mark a non-@objc method from an imported module as
@objc... even though nobody would ever then emit the @objc entry
points for it.

Fixes the rest of rdar://problem/18383574.

Swift SVN r24831
2015-01-29 22:53:53 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Chris Lattner
fe95f81397 introduce a new 'DeclModifier' flag on attributes, which mark that the
attribute is a "modifier" of a decl, not an "attribute" and thus shouldn't
be spelt with an @ sign.  Teach the parser to parse "@foo" but reject it with
a nice diagnostic and a fixit if "foo" is a decl modifier.

Move 'dynamic' over to this (since it simplifies some code), and switch the
@optional and @required attributes to be declmodifiers (eliminating their @'s).



Swift SVN r19787
2014-07-10 05:49:10 +00:00
Chris Lattner
02999cac51 Reinstate the @ on the @objc attribute. This is largely a revert of r19555 with a few tweaks.
Swift SVN r19706
2014-07-08 21:50:34 +00:00
Chris Lattner
7a56499d61 Start making @objc not start with an @ sign:
- Change the parser to accept "objc" without an @ sign as a contextual
   keyword, including the dance to handle the general parenthesized case.
 - Update all comments to refer to "objc" instead of "@objc".
 - Update all diagnostics accordingly.
 - Update all tests that fail due to the diagnostics change.
 - Switch the stdlib to use the new syntax.

This does not switch all tests to use the new syntax, nor does it warn about
the old syntax yet.  That will be forthcoming.  Also, this needs a bit of 
refactoring, which will be coming up.



Swift SVN r19555
2014-07-04 05:57:57 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Ted Kremenek
fa91f5f762 Only allow 'unavailable' methods in protocols that are marked @objc.
These are the same restrictions we have for @optional methods in protocols.

Swift SVN r15645
2014-03-30 08:22:30 +00:00