Commit Graph

43 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
Anthony Latsis
8c1f391878 Gardening: Migrate test suite to GH issues: IDE 2022-08-31 03:00:06 +03:00
Slava Pestov
dac8d666ee Stop passing -requirement-machine-{abstract,inferred,protocol}-signatures flags in tests
These flags are now no-ops.
2022-05-10 12:56:17 -04:00
Slava Pestov
a8190d81da RequirementMachine: Don't record duplicate superclass conflicts 2022-04-01 01:05:54 -04:00
Slava Pestov
494e13c439 GSB: Don't bail out early if some requirements didn't resolve
This doesn't actually matter, except to make the requirement machine
minimization cross-checking work on highly-invalid test cases.
2021-12-08 00:53:35 -05:00
Slava Pestov
f190e51f8d GSB: Diagnose redundant superclass requirements using the redundant requirement graph 2021-04-03 22:33:14 -04:00
Slava Pestov
dcc27ea819 Sema: Fix failure to emit diagnostic with some invalid member type references
There were two problems here:

- isUnsupportedMemberTypeReference() checked if the immediate parent type was
  an unbound generic type, but did not check for the parent of the parent, etc.

- The caller of isUnsupportedMemberTypeReference() had to re-check the
  various invalid conditions to determine what diagnostic to emit, and if
  none of those conditions matched it would just return an ErrorType without
  emitting a diagnostic.

Fix both of these by having isUnsupportedMemberTypeReference() return an
enum indicating what went wrong, and handle more cases.

Fixes <rdar://problem/67292528>.
2020-08-30 00:12:33 -04:00
Slava Pestov
653fa07260 GSB: Fix maybeResolveEquivalenceClass() with member type of superclass-constrained type
Name lookup might find an associated type whose protocol is not in our
conforms-to list, if we have a superclass constraint and the superclass
conforms to the associated type's protocol.

We used to return an unresolved type in this case, which would result in
the constraint getting delayed forever and dropped.

While playing wack-a-mole with regressing crashers, I had to do some
refactoring to get all the tests to pass. Unfortuanately these refactorings
don't lend themselves well to being peeled off into their own commits:

- maybeAddSameTypeRequirementForNestedType() was almost identical to
  concretizeNestedTypeFromConcreteParent(), except for superclasses
  instead of concrete same-type constraints. I merged them together.

- We used to drop same-type constraints where the subject type was an
  ErrorType, because maybeResolveEquivalenceClass() would return an
  unresolved type in this case.

  This violated some invariants around nested types of ArchetypeTypes,
  because now it was possible for a nested type of a concrete type to
  be non-concrete, if the type witness in the conformance was missing
  due to an error.

  Fix this by removing the ErrorType hack, and adjusting a couple of
  other places to handle ErrorTypes in order to avoid regressing with
  invalid code.

Fixes <rdar://problem/45216921>, <https://bugs.swift.org/browse/SR-8945>,
<https://bugs.swift.org/browse/SR-12744>.
2020-05-19 20:28:51 -04: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
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
Robert Widmann
233f8645d1 Move some more common enum diagnostics into the decl checker
In preparation for checkEnumRawValues being turned into a request, move the common diagnostics to the decl checker so they're always emitted at the right time.
2019-09-26 11:07:03 -07:00
Robert Widmann
dce1e2ea32 [Gardening] Remove unnecessary options and files from tests 2019-09-10 18:15:16 -07: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
fischertony
70f8c84af7 Diag: Correct message for protocols with multiple superclass requirements 2019-04-21 17:04:31 +03:00
Doug Gregor
5757d14365 Don’t add RawRepresentation conformance for enums with erroneous raw types
This avoids cascading errors with very unfortunate Fix-Its.
rdar://problem/47891507
2019-02-12 23:12:17 -08:00
Adam Shin
c7e80ebd17 [sema] Update enum error message in tests 2018-10-24 16:35:08 -06:00
Slava Pestov
9ec1926731 Sema: Allow classes in protocol inheritance clauses 2018-07-02 22:06:33 -07:00
Huon Wilson
10c3e6cea9 [GSB] Error types end up as unresolved equivalence classes.
We need to make sure they don't end up as "concrete" equivalence
classes, because they behave more like unresolved ones.

Fixes rdar://problem/40009245.
2018-05-29 16:21:31 -07:00
Doug Gregor
f74dbab453 [AST printer] Print "inheritance" clauses based on the requirement signature.
As we do with "where" clauses, print the "inheritance" clauses of
protocols and associated type declarations using the requirement
signature of the protocol rather than the "inherited" list.
2017-09-08 17:07:09 -07:00
Doug Gregor
cdb38c1e97 [GSB] Check all superclass constraints during finalization.
Use the same infrastructure we have for same-type-to-concrete
constraints to check superclass constraints. Specifically,

* Track all superclass constraints; never "update" a requirement source
* Remove self-derived superclass constraints
* Pick the best superclass constraint within each connected component
  of an equivalence class and use that for requirement generation.
* Diagnose conflicting superclass requirements during finalization
* Diagnose redundant superclass requirements (during finalization)
2017-02-28 16:14:30 -08:00
Doug Gregor
d017fe3ab4 [GenericSigBuilder] Clean up handling of "inheritance" clauses.
Unify the handling of the "inheritance" clauses of a generic type
parameter, associated type, or protocol, walking them in a
TypeRepr-preserving manner and adding requirements as they are
discovered. This sets the stage for providing better source-location
information [*].

This eliminates a redundant-but-different code path for protocol
"inheritance" clauses, which was using
ProtocolDecl::getInheritedProtocols() rather than looking at the
actual TypeReprs, and unifies the logic with that of associated types
and type parameters. This eliminates a near-DRY violation, sets us up
for simplifying the "inherited protocols" part of ProtocolDecl, and
sets us up better for the soon-to-be-proposed

  class C { }
  protocol P: C { }

[*] We still drop it, but now we have a FIXME!
2017-02-17 17:39:10 -08:00
Slava Pestov
3f7a72eb84 Sema: Clean up diagnostic logic when deriving RawRepresentable conformance on enums 2016-12-21 14:20:26 -05: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
Rintaro Ishizaki
d07d0da9ae [Parse] Don't propagate static spelling to AST while parsing top level decls
`FuncDecl` of `static func foo() {}` in top level was accidentally
`isStatic()`. That causes assertion failure in `ASTPrinter`.
2016-10-04 02:55:36 +09:00
SpringsUp
9432a84270 [Diagnostics QOI]: More descriptive errors for synthesized RawRepresentable enums 2016-08-23 01:03:03 +02:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Robert Widmann
f97e5dcb0e [SE-0115][1/2] Rename *LiteralConvertible protocols to ExpressibleBy*Literal. This
change includes both the necessary protocol updates and the deprecation
warnings
suitable for migration.  A future patch will remove the renamings and
make this
a hard error.
2016-07-12 15:25:24 -07:00
Chris Lattner
4db5b98535 fix SR-573 - Crash with invalid parameter declaration
This makes sure to diagnose the error of not having a type on a parameter
in the parser, which is what sema expects.
2016-01-18 09:03:58 -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
Elia Cereda
6e5aac07ce Added test for SR-197 2015-12-18 13:22:23 +01:00
Jordan Rose
6e1bf0d10d Rename @exported to @_exported for now.
At some point I want to propose a revised model for exports, but for now
just mark that support for '@exported' is still experimental and subject
to change. (Thanks, Max.)
2015-11-05 11:59:00 -08:00
Ben Langmuir
3f3d2a9be2 Use the TypeRepr when printing an extension with no extended type
.. which may happen because the extension is in an invalid context.

rdar://problem/22843778

Swift SVN r32342
2015-09-30 18:55:27 +00:00
Chris Lattner
ada5487153 add fixit tests to random other tests.
Swift SVN r31006
2015-08-04 20:35:36 +00:00
Xi Ge
8098f2cc41 [ASTPrinting] Print the types of named patterns appearing in VarDecl.
Swift SVN r29528
2015-06-19 23:41:07 +00:00
Doug Gregor
126e404fe5 Reimplement inference of type witnesses with a separate non-recursive pass.
Inference of type witnesses for associated types was previously
implemented as part of value witness matching in the constraint
solver. This led to a number of serious problems, including:
  - Recursion problems with the solver hunting for a type witness,
  which triggers more attemts to match value witnesses...
  - Arbitrarily crummy attempts to break the recursion causing
  type-check failures in fun places.
  - Ordering dependencies abound: different results depending on which
  value witnesses were satisfied first, failures because of the order
  in which we attempted to infer type witnesses, etc.

This new implementation of type witness inference uses a separate pass
that occurs whenever we're looking for any type witness, and solves
all of the type witnesses within a given conformance
simultaneously. We still look at potential value witnesses to infer
type witnesses, but we match them structurally, without invoking the
constraint solver.

There are a few caveats to this implementation:
  * We're not currently able to infer type witnesses from value
  witnesses that are global operators, so some tricks involving global
  operators (*cough* ~> *cough*) might require some manually-specified
  type witnesses. Note that the standard library doesn't include any
  such cases.

  * Yes, it's another kind of solver. At simple one, fortunately.

On the other hand, this implementation should be a big step forward:
  * It's far more predictable, order-invariant, and non-recursive.
  * The diagnostics for failures to infer type witnesses have
  improved.

Fixes rdar://problem/20598513.

Swift SVN r27616
2015-04-23 00:20:05 +00:00
Jordan Rose
12c80f4a3a Check the raw values of an @objc enum eagerly during decl validation.
For @objc enums, raw values determine the representation values, so we have
to compute them eagerly in order for switch statements to work. Similarly,
if the enum is broken, we have to /fail/ eagerly so that we don't fall down
later on in IRGen.

rdar://problem/19775284

Swift SVN r25282
2015-02-13 20:31:43 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Argyrios Kyrtzidis
1c86427b90 Fix crash when trying to print an inherited type that was not resolved.
Test case on the SourceKit side.
rdar://16706082

Swift SVN r19068
2014-06-21 16:59:29 +00:00
Argyrios Kyrtzidis
43a8d4e285 [AST] Fix crash when printing a function with a missing parameter type.
rdar://17070704

Swift SVN r18665
2014-05-30 00:28:43 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Dmitri Hrybenko
3f15ea9f88 AST printing tests: move error cases to a separate file
This allows us to serialize the non-error cases, and then print the
deserialized AST (not implemented yet).


Swift SVN r8615
2013-09-24 23:58:43 +00:00