Commit Graph

18 Commits

Author SHA1 Message Date
Henrik G. Olsson
cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
Gabor Horvath
6d24c52b80 [cxx-interop] Use the locations imported from C++
A recent PR (#77204) started to import C++ source locations into Swift.
This PR flips a switch so these locations are actually used more widely.
Now some of the diagnostic locations are changed, but they generally
improved the quality of the diagnostics, pointing out conformances
imported from Obj-C code right when they are declared.
2024-11-01 13:49:09 +00:00
Holly Borla
c2594d1338 [FrontendOptions] Remove the -enable-explicit-existential-types flag. 2022-02-17 17:54:59 -08:00
Holly Borla
cf4488922c [ClangImporter] When importing ObjC pointer types, wrap protocol
compositions in ExistentialType when explicit existentials are
enabled.
2022-01-13 19:30:43 -08:00
Luciano Almeida
8f7e929c93 Fixing tests under test/ClangImporter 2019-10-12 23:45:17 -03:00
Doug Gregor
d0dc64ef64 [Clang importer] Type parameters substituted with existentials aren't Hashable
As a follow-on to the fix for rdar://problem/47564982, a type
parameter in a generic Objective-C class whose type bounds include
both a NSObject-derived superclass and a protocol would have been
classified has being Hashable, when in fact the corresponding
existential type will not conform to Hashable. Only allow hashability
when there are no protocol requirements.
2019-02-01 12:39:26 -08:00
Doug Gregor
9084682b00 [Clang importer] Existentials do not conform to Hashable.
Fixes rdar://problem/47564982.
2019-02-01 11:45:16 -08:00
Doug Gregor
d529002009 [Clang importer] Don't bridge blocks to Swift functions in ObjC generic args.
While the compiler can bridge C block types to Swift function types,
the Swift runtime cannot. Don't bridge block types to Swift function
types in Objective-C generic arguments, so

  NSArray<some-block-type>

will get imported as

  [@convention(block) (...) -> Whatever]

rather than

  [(...) -> Whatever]

Fixes rdar://problem/40879067 in a fairly narrow way; the Clang
importer's approach to adjusting types based on context needs a
cleanup, but this is the safe, localized fix suitable for 4.2.
2018-06-15 13:04:30 -07:00
Doug Gregor
37799f44fb [Type checker] Suggest @objc for ill-formed extensions of ObjC generic classes.
@objc is used as a proxy to allow 'self' to access type parameters within
an extension of an Objective-C generic class. Suggest it in cases where it
might make sense.

Clarifies the fix for cases like rdar://problem/27796182.
2018-02-28 22:33:44 -08:00
Jordan Rose
a17f08a2fd [ClangImporter] Generic parameters can be Hashable too! (#10897)
aa215e7e54 made sure we didn't try to construct Sets and Dictionaries
with a non-Hashable key. However, that commit was a little too
restrictive: there was no handling for imported generic parameters
that were constrained to inherit from NSObject. Fortunately,
recovering that information is fairly straightforward.

rdar://problem/33222646
2017-07-11 19:12:47 -07:00
Doug Gregor
aa215e7e54 [Clang importer] Make sure that the first argument of Set/Dictionary types are Hashable.
Extend the check to make sure that the first type argument to an
imported Set or Dictionary type is Hashable actually checks
struct/enum types for Hashable conformances.

Fixes rdar://problem/30622665.
2017-06-26 13:08:39 -07:00
Slava Pestov
f2c46b6629 Add regression test for rdar://30832766, fixed by AnyObject removal 2017-05-07 22:03:18 -07:00
Slava Pestov
e3b68e7bdd Remove -enable-experimental-subclass-existentials staging flag 2017-04-27 20:46:37 -07:00
Slava Pestov
cd1b0d100f ClangImporter: Support for subclass existentials
In Swift 3, an Objective-C type like SomeClass <SomeProtocol> is
imported as SomeClass. The protocol qualification is erased unless
the class bound is 'id' or 'Class'.

Importing such types as class-constrained existentials is a source
breaking change, so the new behavior is only enabled in Swift 4
mode.

Furthermore as a transitional step the staging flag
-enable-experimental-subclass-existentials has to be passed in
also. The flag will soon be removed.
2017-04-19 00:52:14 -07: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
Doug Gregor
dcdef4f7f5 [Type checker] Improve "downcast only unwraps optionals" diagnostics.
Specialize and improve the "downcast only unwraps optionals"
diagnostic to provide specific diagnostics + Fix-Its for the various
casts of forced cast, conditional cast, and "isa" check. Specifically:

* With a forced cast, customize the diagnostic. We still insert the
  appropriate number of !'s, but now we remove the 'as! T' (if an
  implicit conversion would suffice) or replace the 'as!' with 'as'
  (if we still need a bridge)

* With a conditional cast, only emit a diagnostic if we're removing
  just one level of optional. In such cases, we either have a no-op
  (an implicit conversion would do) or we could just use 'as' to the
  optional type, so emit a customized warning to do that. If we are
  removing more than one level of optional, don't complain:
  conditional casts can remove optionals. Add the appropriate Fix-Its
  here.

* With an 'is' expression, only emit a diagnostic if we're removing
  just one level of optional. In this case, the 'is' check is
  equivalent to '!= nil'. Add a Fix-It for that.

Across the board, reduce the error to a warning. These are
semantically-well-formed casts, it's just that they could be written
better.

Fixes rdar://problem/28856049 and rdar://problem/22275685.
2016-12-21 13:47:19 -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
61798ff6ec [test] Rename test/ClangModules to test/ClangImporter. (#5618)
...to match the component in include/ and lib/. No content change.
2016-11-02 18:00:53 -07:00