Commit Graph

269 Commits

Author SHA1 Message Date
Doug Gregor
6e419b6345 Revert "[6.2] Accept @cdecl global functions and enums, behind experimental feature flags" 2025-07-16 10:05:35 -07:00
Alexis Laferrière
731826fd6f Sema: Update other tests for newly more precise diagnostics 2025-07-03 14:11:26 -07:00
Anthony Latsis
7b92a8f041 AST: Quote attributes more consistently in DiagnosticsParse.def 2025-04-23 19:18:11 +01:00
Anthony Latsis
5e41794680 AST: Quote attributes more consistently in DiagnosticsSema.def 2025-04-23 19:18:08 +01:00
Allan Shortlidge
e52a150c6d Tests: Expand tests for @backDeployed diagnostics on Obj-C compatible decls. 2024-11-12 15:11:55 -08:00
Hamish Knight
2d7500eda6 [AST] Remove ParenType
Today ParenType is used:

1. As the type of ParenExpr
2. As the payload type of an unlabeled single
   associated value enum case (and the type of
   ParenPattern).
3. As the type for an `(X)` TypeRepr

For 1, this leads to some odd behavior, e.g the
type of `(5.0 * 5).squareRoot()` is `(Double)`. For
2, we should be checking the arity of the enum case
constructor parameters and the presence of
ParenPattern respectively. Eventually we ought to
consider replacing Paren/TuplePattern with a
PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's
some utility in preserving the sugar of the type
that the user wrote. However it's really not clear
to me that this is particularly desirable since a
bunch of diagnostic logic is already stripping
ParenTypes. In cases where we care about how the
type was written in source, we really ought to be
consulting the TypeRepr.
2024-10-31 11:32:40 +00:00
iMostfa
80a8a0746b Replace uses of the word "accessor" in diagnostics with user-facing terminology (#74462)
In this PR i worked on replacing the word accessor in diagnostics with more user-facing terminologies like setter, getter, didSet Observer, and members based on the context of the message.

in some messages i didn't need to pass DescriptiveDeclKind instead i just changed the text copy itself.

i also updated tests, so you might find it easier to check my changes this way.

Please let me know if there's something i should've done in a better way, and request changes if needed. !

i can squash my commits after reviewing getting the PR Reviewed, just to make it easier to be checked commit by commit

Resolves #55887
2024-08-16 16:29:30 -07:00
Becca Royal-Gordon
07b9fe9ce6 Support @objc(CustomName) on extensions
This now specifies a category name that’s used in TBDGen, IRGen, and PrintAsClang. There are also now category name conflict diagnostics; these subsume some @implementation diagnostics.

(It turns out there was already a check for @objc(CustomName) to make sure it wasn’t a selector!)
2024-05-16 13:40:13 -07:00
Holly Borla
9ba481ad53 [Diagnostics] Clarify the wording of error_in_future_swift_version. 2024-03-01 12:05:51 -08:00
Holly Borla
2a18edc178 [NFC][Concurrency] Update validation tests for @MainActor(unsafe) changes. 2024-01-22 08:43:27 -08:00
Allan Shortlidge
3e16fa4e7e Tests: Remove -enable-swift3-objc-inference from attr_objc.swift.
In preparation for removing support for the `-enable-swift3-objc-inference`
flag entirely, remove its use in attr_objc.swift and update the test
accordingly.
2024-01-11 15:40:04 -08:00
Allan Shortlidge
4eb8ed7182 AST: Trigger HasStorageRequest when retrieving semantic attributes.
When retrieving the full list of semantic attributes for printing, trigger the
HasStorage request to add an implicit `@_hasStorage` attribute if necessary.

Resolves rdar://117768816
2023-11-02 10:18:00 -07:00
Becca Royal-Gordon
8770c7f826 Rework ASTDumper (#68438)
This PR refactors the ASTDumper to make it more structured, less mistake-prone, and more amenable to future changes. For example:

```cpp
  // Before:
  void visitUnresolvedDotExpr(UnresolvedDotExpr *E) {
    printCommon(E, "unresolved_dot_expr")
      << " field '" << E->getName() << "'";
    PrintWithColorRAII(OS, ExprModifierColor)
      << " function_ref=" << getFunctionRefKindStr(E->getFunctionRefKind());
    if (E->getBase()) {
      OS << '\n';
      printRec(E->getBase());
    }
    PrintWithColorRAII(OS, ParenthesisColor) << ')';
  }

  // After:
  void visitUnresolvedDotExpr(UnresolvedDotExpr *E, StringRef label) {
    printCommon(E, "unresolved_dot_expr", label);

    printFieldQuoted(E->getName(), "field");
    printField(E->getFunctionRefKind(), "function_ref", ExprModifierColor);

    if (E->getBase()) {
      printRec(E->getBase());
    }

    printFoot();
  }
```

* Values are printed through calls to base class methods, rather than direct access to the underlying `raw_ostream`.
    * These methods tend to reduce the chances of bugs like missing/extra spaces or newlines, too much/too little indentation, etc.
    * More values are quoted, and unprintable/non-ASCII characters in quoted values are escaped before printing.
* Infrastructure to label child nodes now exists.
    * Some weird breaks from the normal "style", like `PatternBindingDecl`'s original and processed initializers, have been brought into line.
* Some types that previously used ad-hoc dumping functions, like conformances and substitution maps, are now structured similarly to the dumper classes.
* I've fixed the odd dumping bug along the way. For example, distributed actors were only marked `actor`, not `distributed actor`.

This PR doesn't change the overall style of AST dumps; they're still pseudo-S-expressions. But the logic that implements this style is now isolated into a relatively small base class, making it feasible to introduce e.g. JSON dumping in the future.
2023-09-11 23:56:38 -07:00
Becca Royal-Gordon
9c6b3bb6ff Adopt %kind in diag::objc_overriding_objc_decl
Slightly alters wording of a diagnostic.
2023-07-19 13:08:13 -07:00
Becca Royal-Gordon
025728f568 Adopt ValueDecl for invalid redeclaration errors
Causes slight changes to notes on certain `init`s.
2023-07-19 13:08:12 -07:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Allan Shortlidge
022abe4d3b NFC: Update tests to use accepted spelling for @backDeployed. 2023-02-01 22:04:33 -08:00
Allan Shortlidge
5b942eb18b SILGen/Sema: Add @_backDeploy support for constructors.
Resolves rdar://94436652
2023-01-21 18:04:54 -08:00
Allan Shortlidge
8e46b76882 NFC: Update @_backDeploy tests to remove @available attributes where possible. 2023-01-06 08:18:00 -08:00
Dario Rexin
be3249df5b [Sema] Reject @objc functions with incompatible property wrapper in… (#61189)
* [Sema] Reject `@objc` functions with incompatible property wrapper in params

rdar://99443365

When generating `@objc` functions, the parameters were not checked for property wrapper and instead only the wrapped type was checked for compatibility. Added checks and diagnostics for incompatible property wrappers.
2022-09-20 07:12:12 -07:00
Holly Borla
8713d78704 [PrintOptions] Print explicit 'any' in SIL. 2022-08-18 01:15:12 -04:00
Anthony Latsis
85fae6b9ff Gardening: Migrate test suite to GH issues: attr 2022-08-11 18:00:04 +03:00
Josh Soref
dfbf5b635d Spelling attr (#42552)
* spelling: because

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: framework

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instance

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: nonexistent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rewriter

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: versioned

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-22 15:06:07 -07:00
Becca Royal-Gordon
bb29c3589f Merge pull request #41828 from beccadax/a-breach-of-protocol-can-cause-a-conflict
Check protocols for selector conflicts
2022-03-21 14:09:38 -07:00
Allan Shortlidge
59b62c2cc9 NFC: Update tests to include "before: " label in the @_backDeploy attribute. 2022-03-18 11:24:47 -07:00
Becca Royal-Gordon
06949a4f4a Check protocols for selector conflicts
Although we have always checked classes to see if their @objc members had the same selectors, it turns out we never did this for protocols. Oops. Keep a table of ObjC selector names for protocols, just as we do for classes, and diagnose any conflicts between them.

Fixes rdar://80990066.
2022-03-16 14:41:55 -07:00
Allan Shortlidge
3047cd3cce Tests: Account for concurrency availability in attr_backDeploy.swift and move tests for @_backDeploy and @objc interaction to attr_objc.swift. 2022-03-02 00:09:53 -08:00
Doug Gregor
ffd435d4b2 Update test cases for @MainActor inference 2021-11-08 17:13:25 -08:00
Frederick Kellison-Linn
ab7a95c18b [Sema] Delay function representation check until placeholders are bound 2021-08-19 14:53:33 -04:00
Becca Royal-Gordon
866880fdba Soften ObjC selector conflicts from access notes 2021-05-22 13:01:29 -07:00
Becca Royal-Gordon
39115425b7 Rephrase all access note remarks
• There is now one access note success remark and fix-it per declaration, not per attribute/modifier.
• Failure remarks have been rephrased to better emphasize the cause of the failure.
• The wording of other access note remarks and notes have been changed to follow a similar formula.
2021-05-22 13:01:29 -07:00
Becca Royal-Gordon
5dc102badd Don’t emit success remarks for bad @objc names 2021-05-22 13:01:29 -07:00
Becca Royal-Gordon
a414729918 “Wrap” invalid access note diagnostics
This shows up better in Xcode, which unfortunately doesn’t really display notes very clearly.
2021-05-21 16:10:12 -07:00
Becca Royal-Gordon
e611e10b8b Mention access note when describing ObjCReason 2021-05-21 16:10:12 -07:00
Becca Royal-Gordon
801b268239 Emit access note remarks only for valid attributes
This requires deferring emission until the end of typechecking. A future change will emit access-note-related notes when an attribute is invalidated.
2021-05-21 16:10:12 -07:00
Becca Royal-Gordon
69fb104244 Diagnose access note @objc failures using remarks
This commit adds an ObjCReason::ExplicitlyObjCByAccessNote value which diagnoses invalid uses, but using remarks instead of errors so that the failures don’t block builds even with -warnings-as-errors enabled.

This commit also adds annotations to attr/attr_objc.swift to generate a ton of access note test cases from it. In this commit, many of these test cases don’t pass yet. Subsequent commits will fix these bugs.
2021-03-24 14:51:44 -07:00
Becca Royal-Gordon
164b3dcf71 [NFC] Regularize @objc use in attr/attr_objc.swift
To prepare for reuse for access notes.
2021-03-18 17:22:57 -07:00
Robert Widmann
d3eccc39e3 Ban @objc Methods that Introduce Constraints on Contextually Generic Methods
SE-0267 makes this legal in Swift, but these constraints are
unrepresentable in Objective-C and often lead to blow-ups in SILGen when
we construct invalid SIL signatures.

rdar://71845752
2021-02-04 11:33:29 -08:00
Doug Gregor
191a4f8029 [Concurrency] Split @objc checking into a separate test file. 2020-09-04 21:13:17 -07:00
Doug Gregor
84f4cc034f [Concurrency] Finish and add tests for ban on async with @objc. 2020-07-28 16:41:17 -07:00
Hamish Knight
4595f73760 [Sema] Reject an @objc generic subscript
Previously we could allow such a declaration to be
marked @objc, despite being incompatible. This
caused crashes later down the pipeline as the
subscript's accessors were correctly checked for
generic params and were not marked @objc.

Resolves SR-12801.
2020-05-12 21:23:34 -07:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Harlan Haskins
511db0c90a [ModuleInterface] Add printing for new attributes
Specially print @_hasMissingDesignatedInitializers and @_inheritsConvenienceInitializers in module interfaces

Fixes rdar://51249311
2020-01-06 10:15:07 -08:00
Rintaro Ishizaki
4eadbaa9f6 Revert "Merge pull request #27466 from rintaro/syntaxparse-type"
This reverts commit a4fcd26b38, reversing
changes made to 88ecae4b9a.
2019-10-14 12:19:04 -07:00
Slava Pestov
044204a5d5 Sema: Don't synthesize null bodies for invalid accessors
We don't want hasBody() == true and getBody() == nullptr.
2019-10-03 17:11:44 -04:00
Rintaro Ishizaki
7b31d2b4fb [SyntaxParse] Finish type parsing
- Type attributes
- SIL types
2019-10-01 15:40:10 -07:00
Slava Pestov
23edbcaf75 Sema: Merge validateAttributes() into checkDeclAttributes() 2019-08-20 14:47:52 -04:00
Slava Pestov
19d283d9dc AST: Replace ImplicitlyUnwrappedOptionalAttr with Decl::{is,set}ImplicitlyUnwrappedOptional() 2019-08-15 18:41:41 -04:00
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
Slava Pestov
a4bb3101ea Sema: Remove addExpectedOpaqueAccessorsToStorage() 2019-08-06 16:30:13 -04:00