Commit Graph

18 Commits

Author SHA1 Message Date
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
Nishith Shah
8e2e625543 [Diagnostics] Use imperative msg for protocol conformance & switch-case fixits
This commit changes fixit messages from a question/suggestion to an
imperative message for protocol conformances and switch-case. Addresses
https://github.com/apple/swift/issues/67510.
2023-08-13 22:34:26 -07:00
Anthony Latsis
4ee63da498 Gardening: Migrate test suite to GH issues: decl/protocol 2022-08-30 04:08:00 +03:00
Anthony Latsis
103a821838 Sema: Allow non-final classes to satisfy properties and subscripts with covariant Self 2020-09-20 22:33:44 +03:00
Slava Pestov
8f22da205a Sema: Stop wrapping Self returns in protocols with DynamicSelfType 2019-06-26 01:10:11 -04:00
Pavel Yaskevich
91dbcfdfcc [ConstraintSystem] Deplay opening generic requirements until after contextual self has been applied
While computing a type of member via `getTypeOfMemberReference`
let's delay opening generic requirements associated with function
type until after self constraint has been created, that would give
a chance for contextual types to get propagated and make mismatch
originated in generic requirements much easier to diagnose.

Consider following example:

```swift
struct S<T> {}

extension S where T == Int {
  func foo() {}
}

func test(_ s: S<String>) {
  s.foo()
}
```

`foo` would get opened as `(S<$T>) -> () -> Void` and contextual `self`
type is going to be `S<String>`, so applying that before generic requirement
`$T == Int` would make sure that `$T` gets bound to a contextual
type of `String` and later fails requirement constraint `$T == Int`.

This is much easier to diagnose comparing to `$T` being bound to
`Int` right away due to same-type generic requirement and then
failing an attempt to convert `S<String>` to `S<Int>` while simplifying
self constraint.

Resolves: rdar://problem/46427500
Resolves: rdar://problem/34770265
2019-05-24 11:33:30 -07:00
Greg Titus
d20fdf5f82 Merge pull request #19920 from gregomni/8757
[Sema][QoI] Call out missing conformances in protocol witness candidates.
2018-10-22 16:39:51 -07:00
gregomni
939de4fb4a Extend candidate missing conformance checking to other types of requirements so that we check superclass and same type requirements in the same way. 2018-10-19 10:02:30 -07:00
gregomni
42a24ebb71 Use hasDynamicSelfType and add another test where the result type is complex and includes the non-dynamic self. 2018-10-11 13:31:56 -07:00
gregomni
679ac44f1f Add check for dynamic self in the witnessing type, and test. This would also fail to infer previously. 2018-10-09 07:04:07 -07:00
gregomni
eae1015072 Allow associated type inference for requirement returning dynamic Self when witness returns self type and isn't a class or is a final class. (Same as meeting the requirement.) 2018-10-07 09:24:54 -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
Jordan Rose
545b12fa9f Convert backticks to single-quotes in Sema diagnostics
Let's be consistent!
2018-05-09 21:59:39 -07:00
Slava Pestov
510f842488 AST: Workaround for same-type constraints getting dropped from requirement environment
The fix for <https://bugs.swift.org/browse/SR-617> introduced
a new kind of requirement environment where 'Self' remains a
generic parameter, but receives a class constraint, instead of
becoming fully concrete.

As before, we would form the synthetic signature by taking
the generic signature of the requirement, and substituting it
the new 'Self' type.

However, whereas previously the 'Self' type was always concrete
and any DependentMemberTypes in the requirement's signature
would become concrete type references, with a class-constrained
'Self' the DependentMemberTypes remain.

Apparently, the GSB cannot handle DependentMemberTypes where
the base is class-constrained.

Work around this by ensuring that we add a conformance constraint
for the 'Self' parameter to the protocol in question, which
allows the DependentMemberTypes to be correctly resolves once
the conformance is made concrete by a superclass constraint.

The FIXME comment being removed here references crashes which
no longer seem to reproduce, so I'm assuming some underlying
GSB issues got fixed and the FIXME is clearly no longer necessary.

However, I still consider this fix somewhat unsatisfying, because
it is not clear if there's some deeper flaw in how the GSB
models superclass constraints. It might resurface again in the
future.

Fixes <rdar://problem/39419121>, <https://bugs.swift.org/browse/SR-7428>.
2018-04-16 22:22:52 -07:00
Slava Pestov
08e4e7c990 Add test for https://bugs.swift.org/browse/SR-7422 2018-04-13 13:33:23 -07:00
Slava Pestov
7cbd0c0b37 Sema: Lift restriction on classes conforming to protocols with default implementations returning 'Self'
Now that we pass in the correct type metadata for 'Self', it is
sound for a class to conform to a protocol with a default implementation
for a method returning 'Self'.

Fixes <rdar://problem/23671426>.
2017-10-09 19:53:51 -07:00
Jordan Rose
192b523a8e Revert "Fix issue with 'Self' metadata when class conforms to protocol with default implementations" (#12344)
It broke the 32-bit iOS simulator, and possibly the 64-bit simulator as well. Reverts 5618553.
2017-10-09 10:02:48 -07:00
Slava Pestov
80ada27707 Sema: Lift restriction on classes conforming to protocols with default implementations returning 'Self'
Now that we pass in the correct type metadata for 'Self', it is
sound for a class to conform to a protocol with a default implementation
for a method returning 'Self'.

Fixes <rdar://problem/23671426>.
2017-10-09 00:53:03 -07:00