Commit Graph

9 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
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
Luciano Almeida
1184492d25 [Diagnostics] SR-11419 Diagnose protocol stub note in editor mode only (#28101)
* [TypeChecker] Enclosing stubs protocol note within editor mode

* [test] Removing note from test where there is no -diagnostics-editor-mode flag

* Formatting modified code

* [tests] Fixing tests under validation-tests
2019-11-06 07:42:48 -08:00
Xi Ge
1535bea268 FixCode: issue a separate note for protocol-stub fixit when the fixit location is in another file
Under non-editor mode, the fixit for inserting protocol stubs is associated with a note
pointing to the missing protocol member declaration which could stay in a separate file from
the conforming type, leading to the behavior of rdar://51534405. This change checks if
the fixit is in a separate file and issues another note to carry the fixit if so.

rdar://51534405
2019-07-10 12:30:54 -07:00
Jordan Rose
986e093e3b [ClangImporter] Remove support for Swift 3 mode (#17722)
Not as exciting as some of the other components, but still!
2018-07-16 17:59:42 -07:00
Jordan Rose
adac80fa02 [ClangImporter] Handle inheritance from a class/protocol composition (#12067)
This is legal Objective-C code:

    typedef NSBar <NSFooing> BarAndFoo
    @interface MyBaz : BarAndFoo
    @end

    // Equivalent
    @interface MyBaz : NSBar <NSFooing>
    @end

In Swift 3, we usually handled these by just dropping the protocol
part, making everything appear to work. (The protocols get added to
the class later, without looking at sugar.) However, in Swift 4, we
started supporting these compositions directly* and suddenly
inheriting from them didn't work (read: crashed the compiler). As an
extra twist, even Swift 3 can hit the problem case when the base type
is NSObject, because we figured 'id <NSObject, NSFooing>' was a better
approximation of 'NSObject <NSFooing> *' than 'NSObject *' was.

Fix this by just ignoring protocols when looking for a superclass. As
mentioned, we attach those separately anyway, so we aren't losing any
information.

* This isn't exactly true; there's still a difference between
'NSBar <NSFooing>' and 'NSBar <NSFooing> *'. Jacopo Andrea Giola fixed
a previous issue with this in a598277ad. But Swift doesn't do anything
meaningful with the first form, so it usually just pretends it's the
second.

rdar://problem/34586035
2017-09-25 11:33:17 -07:00
Slava Pestov
ac8e0376a2 Sema: Fix requirement/witness disambiguation for subclass existentials
When performing a lookup into a class C, we might find a member of
C that witnesses a requirement in a protocol Q that C conforms to.

In this case, AST name lookup returns both results.

There are two further levels of fitering which can eliminate the
ambiguity:

- Sema name lookup maps requirements to witnesses if the base type
  of the lookup is a nominal type or a class-constrained archetype.

  Imported conformances don't have this mapping recorded, but there's
  another hack in this code path where if a requirement maps to
  itself inside a conformance, it is dropped from the results
  altogether.

- If the duplicate results were not filtered out in Sema name lookup,
  there was another hack in CSRanking which would a witness higher
  than it's requirement when comparing solutions. This doesn't work
  for imported conformances, but usually name lookup filters out
  the duplicate results sooner, which also eliminates the exponential
  behavior from having multiple constraint system solutions.

However, if we have a subclass existential C & P where C conforms
to Q and we find a member of C that witnesses a requirement of Q,
then (C & P) does not conform to Q.

So if the conformance was imported, *both* of the above checks
would fail to disambiguate the witness and requirement, and the
member access would fail to type check.

To make this work with imported conformances, teach Sema name lookup
to extract the superclass from an existential before performing the
conformance check. If the conformance check fails, it means we
found the protocol member via the 'existential' part of the subclass
existential (eg, in our case, a member of P), and we proceed as
before.

Fixes <rdar://problem/33291112>.
2017-07-27 23:18:01 -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