Commit Graph

26 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
Harlan Haskins
4ac34a40ea @retroactive conformance syntax and checking (#36068) 2023-10-20 14:27:03 -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
b2e2bab7e0 DiagnosticEngine: Print any in 'aka' types 2022-05-29 21:55:31 +03:00
Anthony Latsis
ba7f301e83 ConformanceChecker: Always diagnose a conformance failure if the requirement check fails in 'ensureRequirementsAreSatisfied' 2022-03-28 23:22:36 +03:00
Anthony Latsis
f39464bbf3 TypeChecker: Replace calls to the old 'checkGenericArguments' with 'checkGenericArgumentsForDiagnostics' 2022-03-28 22:55:02 +03:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Anthony Latsis
6e8dcbe745 ConformanceChecker: Resolve value witnesses unless they depend on invalid type witnesses 2022-02-26 01:06:53 +03: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
Greg Titus
7d0bdb112e Omit protocol match diagnosis for constructors with differing names. 2018-10-14 17:08:50 -07:00
Doug Gregor
9b2c462709 [Conformance checking] Factor out associated type inference.
Move associated type inference into its own class, to make this
code easier to understand/maintain/improve. Minor diagnostics changes
because we're properly passing uninference associated type declarations
to the "group" checker.
2017-12-09 23:05:24 -08:00
Slava Pestov
4e8bdcd716 Sema: Type aliases with an unbound generic type cannot witness associated type requirements
We allow definitions like this:

struct G<T> {}
typealias A = G

As a shorthand for

typealias A<T> = G<T>

A typealias like this cannot satisfy an associated type requirement
for the same reason that a generic typealias cannot satisfy an
associated type requirement, which was already handled.

Previously this would crash in the type checker or in IRGen.

This fixes a weird regression in a fixed compiler crasher from the
next patch.
2017-11-04 23:40:23 -07:00
Mark Lacey
ceacfb4c53 Make getWitnessType() return Type() for ErrorType.
None of the clients of this care about distinguishing between immediate
failures in getWitnessType() vs. earlier errors that result in
getWitnessType() returning ErrorType, so simplify the interface by
having it always return Type() if there is a problem.

Update the clients that were not already checking for null result to do
so.

Fixes rdar://problem/32215763.
2017-05-22 14:33:00 -07:00
Slava Pestov
e58ae766a3 Fix and un-XFAIL regressed crashers from recent stdlib change 2017-05-17 05:51:51 -07:00
Doug Gregor
3dbfa9789f [Associated type inference] Check solutions against full requirement signature
When we have a potential assignment of associated types to type
witnesses during associated type inference, check that set of type
witnesses against the requirements in the requirement signature, so
that we can reject any solutions that fail some of the protocol's
requirements.

This is most of rdar://problem/31830524 --- but gets thwarted by the
inability of associated type inference to work across multiple
protocols.
2017-05-04 00:21:52 -07:00
Slava Pestov
45ef0f5dfb Sema: Generic types cannot witness associated type requirements
Until recently we didn't allow nested generic types at all.
In Swift 3, generic typealiases were added, and we forgot to
guard against them in witness matching, leading to a crash if
a generic typealias witnesses an associated type requirement.

Now that nested generic nominals are allowed too, add a check.

The diagnostic is not very good, but I'll revisit this later.
2016-12-18 22:34:16 -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
Doug Gregor
50341da32b Use "TypeBase::hasError()" rather than "is<ErrorType>()" where needed.
In most places where we were checking "is<ErrorType>()", we now mean
"any error occurred". The few exceptions are in associated type
inference, code completion, and expression diagnostics, where we might
still work with partial errors.
2016-10-07 10:58:23 -07:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Doug Gregor
38c1de69e4 Reinstate "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit ce7b2bcf09, tweaking
a few validation tests appropriately (1 crasher fixed, two -verify
tests that needed updating).
2016-01-14 00:21:48 -08:00
Erik Eckstein
ce7b2bcf09 Revert "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit 2b2e9dc80e.

It broke some compiler crasher tests
2016-01-13 20:42:58 -08:00
gregomni
2b2e9dc80e [SR-511][Parse] Add 'associatedtype' keyword and fixit
Adds an associatedtype keyword to the parser tokens, and accepts either
typealias or associatedtype to create an AssociatedTypeDecl, warning
that the former is deprecated. The ASTPrinter now emits associatedtype
for AssociatedTypeDecls.

Separated AssociatedType from TypeAlias as two different kinds of
CodeCompletionDeclKinds. This part probably doesn’t turn out to be
absolutely necessary currently, but it is nice cleanup from formerly
specifically glomming the two together.

And then many, many changes to tests. The actual new tests for the fixits
is at the end of Generics/associated_types.swift.
2016-01-13 17:54:31 -08:00
Maxim Moiseev
0e0191380a OptionSetType => OptionSet 2015-12-10 14:58:24 -08:00
Doug Gregor
4b82904371 Don't allow silent failures in protocol conformances.
As of r31224, we tried to suppress redundant protocol-conformance
diagnostics for witnesses that look like they could have matched
something in an unconstrained protocol extension. However, this was
allowing ill-formed conformances to be accepted, causing a crash in
the AST verifier. Fixes rdar://problem/23033862.

Swift SVN r32671
2015-10-13 21:30:20 +00:00
Jordan Rose
f1b04beaa3 Don't complain about missing witnesses if they're available in extensions.
(Specifically, unconstrained extensions.)

This removes the problem where trying to conform to a protocol spits out
a dozen errors about missing requirements in a base protocol, but eleven
of them have a sensible default implementation with no constraints. This
is "P6" in the test cases; the others all passed before.

There's still plenty more work in this space. In particular, if an
associated type is missing we just give up rather than encouraging people
to provide the members it would be inferred from.

Swift SVN r31224
2015-08-13 20:49:26 +00:00