Commit Graph

113 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
Slava Pestov
7909d83229 AST: Refactor directReferencesForTypeRepr() to track inverses 2024-02-24 07:25:59 -05:00
Kavon Farvardin
f296d8e158 NCGenerics: mass XFAIL tests
It's easier to get a handle on regressions while working through
failures if the tests that are known to not pass are XFAIL'd for
NoncopyableGenerics.
2024-02-20 18:26:05 -05:00
Slava Pestov
ea15d9f9b2 Stop passing -warn-redundant-requirements in tests 2024-02-02 14:57:19 -05:00
Anthony Latsis
0c749b2651 Gardening: Migrate test suite to GH issues: decl/ext 2022-08-26 03:26:32 +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
f39372b33d RequirementMachine: Turn off redundant requirement warnings by default and add -warn-redundant-requirements frontend flag 2022-05-10 01:49:56 -04:00
Slava Pestov
b4b873332f Update -requirement-machine-* flags in various tests
- Don't pass 'verify' since it's now the default
- Update tests where diagnostics changed in a correct way to pass 'on' instead
- Delete compiler_scale/explicit_requirements_perf.swift since it's not testing anything with the requirement machine
2022-03-31 15:57:36 -04:00
Pavel Yaskevich
b4976df82c [Diagnostics] Adjust missing conformance note to use ':' instead of '==' 2021-06-25 12:05:47 -07: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
Holly Borla
1a628f3107 [Diagnostics] Simplify logic in diagnoseAmbiguityWithFixes for emitting
the ambiguity diagnostic by combining a few special errors into one.
2020-02-11 14:53:27 -08:00
Slava Pestov
1df3d1a33c Frontend: Don't interleave parsing and typechecking for the main file
SIL files still require this behavior; if we cleaned that up we
could simplify a fair bit of code here.

Fixes <https://bugs.swift.org/browse/SR-284>,
<https://bugs.swift.org/browse/SR-4426>.
2019-12-05 08:45:55 -05:00
Varun Gandhi
0dcb936531 Serialize extended nominal separately when serializing an extension.
Instead of computing it from the extended type after deserialization --
which is tricky to do, due to potential presence of protocol
compositions -- we obtain the extended nominal directly.

Fixes SR-11227 and linked rdar://problem/53712389.
2019-09-05 15:33:02 -07:00
Pavel Yaskevich
783add0ea4 [CSDiagnostics] Split no exact match diagnostic into three choices
1. If this is a special name avoid printing it because
   printing kind is sufficient;

2. If all of the labels match, print a full name;

3. If labels in different choices are different, it means
   that we can only print a base name.
2019-07-22 12:32:17 -07:00
Pavel Yaskevich
caf266f4b1 [CSDiagnostics] Use special error message when call didn't match exactly
For multiple solutions with fixes for the same call, replace
`ambiguous reference` diagnostic with the one that explicitly
mentions that there are no exact matches, and provide partially
matched candidates as notes.
2019-07-22 11:20:56 -07:00
Suyash Srijan
0d9f63474a [Sema] Emit a diagnostic when extending a protocol with a redundant requirement (#20503)
* Emit a warning diagnostic if an extension contains a redundant requirement

* Updates diagnostic message and checks if the extension type is a protocol

* Updates indentation and extracts self type

* [ast] Updates diagnostic message

* [ast] fix indentation

* [ast] Change ':' to 'to' in 'protocol_extension_redundant_requirement'

* [sema] Adds protocol extension redundant requirement check

Moved from TypeCheckRequests to TypeCheckGeneric

* [ast] fix some crashes related to null ptrs, check self type before emitting a diagnostic, update tests

* [ast] renames 'owner' to 'ext'

* [sema] fix style

* [test] Add another test case for redundant requirement

Co-Authored-By: theblixguy <suyashsrijan@outlook.com>

* [test] fix failing test

The test was failing because A has already been declared as a typealias.
2018-11-15 19:18:51 -08:00
gregomni
b7df1ca1df Re-try a failingConstraint during salvage now that attemptFixes is turned on. This enables better missing conforms-to diagnoses. 2018-10-13 20:06:19 -07:00
Pavel Yaskevich
63b802ca88 [AST/Printing] Don't omit empty labels in special names
This makes diagnostics more verbose and accurate, because
it's possible to distinguish how many parameters there are
based on the message itself.

Also there are multiple diagnostic messages in a format of
`<descriptive-kind> <decl-name> ...` that get printed as
e.g. `subscript 'subscript'` if empty labels are omitted.
2018-09-24 18:36:53 -07:00
Jordan Rose
5dace224a0 Merge pull request #18623 from dingobye/sr8453
[Sema] Warn for redundant access-level modifiers on setters or used in an extension.
2018-09-05 17:44:26 -07:00
Pavel Yaskevich
16fc3117cc [ConstraintSystem] Diagnose ambiguities related to solutions with fixes
If all of the solutions in the set have a single fix, which points
to the common anchor, attempt to diagnose the failure as an
ambiguity with a list of candidates and their related problems as notes.

Having richer message like that helps to understand why something is
ambiguous e.g. if there are two overloads, one requires conformance
to some protocol and another has a same-type requirement on some type,
but neither matched exactly, having both candidates in the diagnostic
message with associated errors, instead of simplify pointing to related
declarations, helps tremendously.
2018-08-24 11:20:49 -07:00
Pavel Yaskevich
3cc613497c [ConstraintSystem] Add same-type requirement fix/diagnostic
Extend new requirement failure diagnostics by adding "same-type"
generic requirement failures.
2018-08-18 13:05:32 -07:00
Ding Ye
f34020bfd4 [Sema] Warn when redundant access-level modifier is added in an extension.
This patch adds warning for redundant access-level modifiers
used in an extension. It also refines the diagnostics of
access_control_ext_member_more issues, in case the fixit
could suggest redundant modifiers.

Resolves: SR-8453.
2018-08-10 14:33:16 +10:00
Pavel Yaskevich
ba085e5bdc [Diagnostics] Improve missing conformance diagnostics for sub-types and members
If generic parameter associated with missing conformance comes
from different context diagnose the problem as "referencing" a
specific declaration from affected type.
2018-08-07 18:55:43 -07:00
Pavel Yaskevich
ad171e05cc [Diagnostics] Improve missing conformance diagnostics by using affected declaration
Instead of simply pointing out which type had conformance failures,
let's use affected declaration instead, which makes diagnostics much
richer e.g.

```
'List<[S], S.Id>' requires that 'S.Id' conform to 'Hashable'
```

versus

```
initializer 'init(_🆔)' requires that 'E' conform to 'Hashable' [with 'E' = 'S.Id']
```

Since latter message uses information about declaration, it can also
point to it in the source. That makes is much easier to understand when
problem is related to overloaded (function) declarations.
2018-08-07 12:59:53 -07:00
Pavel Yaskevich
c2bf3d5ba9 [TypeChecker] NFC: Fix all of the diagnostics improved by conformance tracking 2018-08-02 21:55:16 -07:00
Slava Pestov
3937732b9b Add more tests for protocols with superclass 2018-07-09 23:56:25 -07:00
Matt Diephouse
87aaf10e6b [Diagnostics] Improve error when type parameters aren't equal 2018-06-15 15:08:05 -04:00
Pavel Yaskevich
5f222ec36d [Diagnostics] Improve diagnostics for type parameter requirements
Detect and diagnose failures in constraints representing
type parameter requirements generated by `openGeneric`.

Resolves: rdar://problem/35890334
2018-03-27 00:11:57 -07:00
Doug Gregor
3883ff0b29 [Type checker] Suppress near-miss warnings within the type definition.
There are a number of things that can only be written within the main
type definition (e.g., required initializers, stored properties),
making it far more likely that we'll get false positives from the
newly-introduced "near-miss" warnings for protocol
conformances. Moreover, sometimes a number of protocol conformances
are placed on the main type definition, increasing the potential for
false positives.

Suppress near-miss warnings for potential candidates when the protocol
conformance is stated on the main type definition itself. Therefore,
we only perform near-miss checking of non-@objc requirements when the
conformance itself was declared on an extension, which is roughly the
development style that near-miss warnings favor.

Fixes rdar://problem/37283860.
2018-02-13 11:46:43 -08:00
Slava Pestov
336a97bc1a Sema: Diagnose invalid 'self.init' delegation where 'self' is an archetype
This is a corner case but would previously lead to a compiler crash
or miscompile.

Fixes <rdar://problem/21991470>, <https://bugs.swift.org/browse/SR-5022>.
2017-12-08 17:46:16 -08:00
Doug Gregor
318a455314 [Type checker] Suppress near-miss warnings for unlabeled inits and subscripts.
Suggested by @brentdax, thanks!
2017-11-07 17:02:36 -08:00
Doug Gregor
493d4da667 Warn on “near-misses” when defaults are used for protocol witnesses.
When a particular nominal type or extension thereof declares conformance
to a protocol, check whether that type or extension contains any members
that *nearly* match a defaulted requirement (i.e., a requirement that 
is satisfied by something in a protocol extension), but didn’t match
for some reason and weren’t used to satisfy any other requirement of
that protocol. It’s intended to catch subtle mistakes where a default
gets picked instead of the intended member.

This is a generalization of the code we’ve had for @objc optional
requirements for a long time.

Fixes rdar://problem/24714887.
2017-10-26 17:04:46 -07:00
Slava Pestov
edfaf7f724 Sema: Fix name lookup of nominal types nested inside a class from a protocol 2017-08-06 00:21:49 -07:00
Slava Pestov
fdd0259f7f Sema: Lift obsolete restriction on protocol extensions via typealias 2017-06-21 00:44:33 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Slava Pestov
7f3c97bf8b AST: More consistent spelling of 'type alias' in diagnostics
Some messages said 'typealias' and others said 'type alias'.
Change everything to use 'type alias' consistently (except
when it's talking about the keyword itself).
2017-04-23 00:02:30 -07:00
Slava Pestov
54883e82e4 Sema: Fix type lookup from protocol extensions with a class-constrained 'Self'
A protocol extension can add additional generic constraints on
'Self' or associated types thereof. In particular, 'Self' itself
can have a superclass constraint placed on it.

There were a couple of problems with this corner case:

- Type aliases defined in protocols that 'Self' conforms to _as a
  concrete type_ to were not handled properly, triggering an assertion.

  For example,

  protocol P { typealias T = ... }
  class C : P {}
  protocol Q {}

  extension Q where Self : C { ... T ... }

  The conformance o P comes from the 'Self : C' constraint.

- If the type was found in a superclass of 'Self', we used the wrong
  base type for the substitution.

  For example,

  protocol P {}
  class C<T> { typealias A = T }
  class D : C<Int> {}

  extension P where Self : D { ... A ... }

  The substituted type of 'A' should be computed with a self type
  of C<Int> here.

Also, take another stab at cleaning up the mess that is
resolveTypeInContext() and related bits of code.
2017-04-10 17:04:37 -07:00
Brian King
29c1fc472b Generate an error message on protocol extensions with the final attribute. 2017-03-09 14:18:39 -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
Doug Gregor
f168e7270c [Type checker] Use DependentMemberType instead of type variables for nested types.
In the constraint solver, we've traditionally modeled nested type via
a "type member" constraint of the form

  $T1 = $T0.NameOfTypeMember

and treated $T1 as a type variable. While the solver did generally try
to avoid attempting bindings for $T1 (it would wait until $T0 was
bound, which solves the constraint), on occasion we would get weird
behavior because the solver did try to bind the type
variable.

With this commit, model nested types via DependentMemberType, the same
way we handle (e.g.) the nested type of a generic type parameter. This
solution maintains more information (e.g., we know specifically which
associated type we're referring to), fits in better with the type
system (we know how to deal with dependent members throughout the type
checker, AST, and so on), and is easier to reason able.

This change is a performance optimization for the type checker for a
few reasons. First, it reduces the number of type variables we need to
deal with significantly (we create half as many type variables while
type checking the standard library), and the solver scales poorly with
the number of type variables because it visits all of the
as-yet-unbound type variables at each solving step. Second, it
eliminates a number of redundant by-name lookups in cases where we
already know which associated type we want.

Overall, this change provides a 25% speedup when type-checking the
standard library.
2016-11-05 23:20:28 -07:00
Slava Pestov
c7089ff000 Sema: Add support for extensions of nested generic types 2016-11-03 22:20:30 -07:00
Pavel Yaskevich
02cae22541 [Diagnostics] Extend contextual failure checking to all apply expressions
As an extension of SR-2208 apply contextual conversion failure checking
to all of the expressions diagnosed via FailureDiagnosis::visitApplyExpr.

Resolves <rdar://problem/28909024>.
2016-10-30 22:28:26 -07:00
Argyrios Kyrtzidis
69918a966d [ASTPrinter] Fix printing of nested typealias types and make it consistent with printing of nominal types.
This fixes several issues:
- By default parent types of alias types are not printed which results in
	- Erroneous fixits, for example when casting to 'Notification.Name' from a string, which ends up adding erroneous cast
	  as "Name(rawValue: ...)"
	- Hard to understand types in code-completion results and diagnostics
- When printing with 'fully-qualified' option typealias types are printed erroneously like this "<PARENT>.Type.<TYPEALIAS>"

The change make typealias printing same as nominal types and addresses the above.
2016-08-11 12:15:15 -07:00
David Farler
7bfaeb57f1 [SE-0081] Warn on deprecated where clause inside angle brackets
and provide a fix-it to move it to the new location as referenced
in SE-0081.

Fix up a few stray places in the standard library that is still using
the old syntax.

Update any ./test files that aren't expecting the new warning/fix-it
in -verify mode.

While investigating what I thought was a new crash due to this new
diagnostic, I discovered two sources of quite a few compiler crashers
related to unterminated generic parameter lists, where the right
angle bracket source location was getting unconditionally set to
the current token, even though it wasn't actually a '>'.
2016-07-26 01:41:10 -07:00
Xi Ge
5218c2cf7a [Sema] Add note to all unresolved witness types instead of just the first one. (#3458)
When issuing the error of "not conforming to a protocol P", we used to only note the first
unresolved witness type. This is inconsistent with the situation when the conformance
fails due to unimplemented functions, which we note all of the unimplemented functions.
This patch fixed this by noting all unresolved witness types.
2016-07-12 16:41:03 -07:00
Slava Pestov
7814c47b71 AST: Slightly change meaning of NominalTypeDecl::getDeclaredType()
Consider this code:

struct A<T> {
  struct B {}
  struct C<U> {}
}

Previously:

- getDeclaredType() of 'A.B' would give 'A<T>.B'
- getDeclaredTypeInContext() of 'A.B' would give 'A<T>.B'

- getDeclaredType() of 'A.C' would give 'A<T>.C'
- getDeclaredTypeInContext() of 'A.C' would give 'A<T>.C<U>'

This was causing problems for nested generics. Now, with this change,

- getDeclaredType() of 'A.B' gives 'A.B' (*)
- getDeclaredTypeInContext() of 'A.B' gives 'A<T>.B'
- getDeclaredType() of 'A.C' gives 'A.C' (*)
- getDeclaredTypeInContext() of 'A.C' gives 'A<T>.C<U>'

(Differences marked with (*)).

Also, this change makes these accessors fully lazy. Previously,
only getDeclaredTypeInContext() and getDeclaredIterfaceType()
were lazy, whereas getDeclaredType() was built from validateDecl().

Fix a few spots where the return value wasn't being checked
properly.

These functions return ErrorType if a circularity was detected via
the generic parameter list, or if the extension did not resolve.
They return Type() if the extension cannot be resolved *yet*.

This is pretty subtle, and I'll need to do another pass over
callers of these functions at some point. Many of them should be
moved over to use getSelfInContext(), getSelfOfContext() and
getSelfInterfaceType() instead.

Finally, this patch consolidates logic for diagnosting invalid
nesting of types.

The parser had some code for protocols in bad places and bad things
inside protocols, and Sema had several different bail-outs for
bad things in protocols, nested generic types, and stuff nested
inside protocol extensions.

Combine all of these into a single set of checks in Sema. Note
that we no longer give up early if we find invalid nesting.
Leaving decls unvalidated and un-type-checked only leads to
further problems. Now that all the preliminary crap has been
fixed, we can go ahead and start validating these funny nested
decls, actually fixing some crashers in the process.
2016-06-18 17:15:24 -07:00
Trent Nadeau
0cc851568a Updated tests to use @discardableResult and _ = . 2016-05-11 22:53:38 -04:00
Dmitri Gribenko
10697f939f Merge commit '510f29abf77e202780c11d5f6c7449313c819030' into swift-3-indexing-model 2016-04-14 13:45:27 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Shawn Erickson
fe9482b6bb New indexing model: WIP fixed compile issues in various stdlib tests 2016-03-13 21:00:01 -07:00