Commit Graph

2381 Commits

Author SHA1 Message Date
Slava Pestov
0be55c130d GSB: Use redundant requirement graph in enumerateRequirements() 2021-03-01 17:50:26 -05:00
Dario Rexin
8e0a260414 [Sema]: Add Codable synthesis for enums with associated values (#34855)
* [Sema]: Add Codable synthesis for enums with associated values

* Incorporate review feedback for enum Codable synthesis

* Implement enum specific versions of existing Codable tests

* Encode parameterless enum cases as

* Add test for overloaded case identifiers

* Align code generation with latest proposal revision

* Put enum codable derivation behind flag

* clang-format sources

* Address review feedback and fix tests

* Add diagnostic for conflicting parameter identifiers

* Restructure code after rebase
2021-02-26 17:20:34 -08:00
Rintaro Ishizaki
26aa91e660 Merge pull request #35230 from mininny/default-accessor-error-in-protocol
[Diagnostics] Improve diagnostic for defaulted accessor in a protocol property.
2021-02-24 10:17:53 -08:00
Pavel Yaskevich
74d2a6c700 [ConstraintSystem] Limit static member reference on protocol metatype to leading dot syntax only
Do not allow references to a static members with explicitly specified
protocol metatype base, limit that to leading dot syntax only.
2021-02-23 11:33:11 -08:00
Pavel Yaskevich
30f255755b [Diagnostics] NFC: Adjust all diagnostics improved/changed by static member refs on protocol metatypes feature 2021-02-23 11:33:10 -08:00
Pavel Yaskevich
7009207491 [ConstraintSystem] Adjust handling of incorrect member references on protocol metatypes
Since it's now possible to refer to static members declared on a protocol
metatype if result type conforms to the protocol we need to adjust failure
detection to identify that conformance failure means and invalid reference
in certain situations.
2021-02-23 11:32:24 -08:00
Robert Widmann
b8329b633e Merge pull request #36060 from CodaFi/codicil
Patch a Huge Soundness Hole in Codable Synthesis
2021-02-22 08:48:50 -08:00
Doug Gregor
d9e4184742 Make Error and CodingKey conform to ConcurrentValue.
Make both Error and CodingKey conform to ConcurrentValue, so that
thrown errors always conform to ConcurrentValue. Downgrade (to
warnings) and ConcurrentValue-related diagnostics that are triggered
by this change in existing Error and CodingKey-conforming types to
reduce the impact on source compatibility.
2021-02-20 22:01:28 -08:00
Robert Widmann
6c9fb0d55c Undo Bogus DiagnosticTransactions in Codable Synthesis
The order of diagnostic emission absolutely does not matter. What this transaction was actually doing was suppressing valid diagnostics. This is a deeply unsound thing to do since if errors are emitted but Codable synthesis succeeds then invalid code can make its way past Sema.

rdar://74392492
2021-02-19 16:58:38 -08:00
Anthony Latsis
a223d37ae7 Merge pull request #34140 from AnthonyLatsis/coself-array
AST, Sema: Teach findProtocolSelfReferences that some stdlib collections preserve variance
2021-02-13 19:45:15 +03:00
Minhyuk Kim
518e1b0a59 [Parse] Improve error for defaulted accessor in a protocol property. SR-13963 2021-02-12 22:40:33 +09:00
Slava Pestov
2d37b84aca Merge pull request #35909 from slavapestov/existential-type-unsupported-trigger
Sema: Don't need to explicitly calculate existentialTypeSupported()
2021-02-11 11:49:12 -05:00
Robert Widmann
e3c1c42576 Merge pull request #35894 from CodaFi/semantic-members-only
Look Through Class-Bound Archetypes When Installing Semantic Members
2021-02-11 07:26:16 -08:00
Slava Pestov
b81afe3c51 Sema: Don't need to explicitly calculate existentialTypeSupported() 2021-02-11 00:19:24 -05:00
Anthony Latsis
06ceb19ccf Diag: Fix inaccuracy in dynamic_self_invalid 2021-02-11 03:22:20 +03:00
Anthony Latsis
3d317938ad AST, Sema: Teach findProtocolSelfReferences that some stdlib collections preserve variance
* Swift.Array preserves variance in its 'Element' type
* Swift.Dictionary preserves variance in its 'Value' type
2021-02-11 03:22:20 +03:00
Robert Widmann
34ade3cc66 Also Look Though Class-Bound Protocol Compositions 2021-02-10 14:54:08 -08:00
Robert Widmann
09d540ac71 Look Through Class-Bound Archetypes When Installing Semantic Members
Before lookup was requestified, the entire lookup stack would
install semantic members. As this caused cycles in the lookup path, it
was refactored to instead only occur at the TypeChecker::lookup*
entrypoints. Unfortunately, these entrypoints were not kept in sync with
the stack building code in qualified lookup, so a case was missed:
class-bound archetypes. We need to synthesize semantic members for them
as well or we'll non-deterministically fail to find synthesizable
members in incremental mode.

rdar://74174749
2021-02-10 14:54:04 -08:00
Slava Pestov
07bd07926f AST: Implement extractNearestSourceLoc() for ProtocolConformance 2021-02-10 16:30:30 -05:00
Evan Wilde
8b80331c3d Updating tests to use actor
This patch updates the `actor class` spelling to `actor` in almost all
of the tests. There are places where I verify that we sanely handle
`actor` as an attribute though. These include:

 - test/decl/class/actor/basic.swift
 - test/decl/protocol/special/Actor.swift
 - test/SourceKit/CursorInfo/cursor_info_concurrency.swift
 - test/attr/attr_objc_async.swift
 - test/ModuleInterface/actor_protocol.swift
2021-02-10 08:09:13 -08:00
Robert Widmann
ddd1cd9776 Merge pull request #35831 from CodaFi/extended-extracts
Some Cleanup Of Overriding Diagnostics
2021-02-09 16:55:07 -08:00
Slava Pestov
6c5e51621c Sema: Allow an enum case to witness a throwing static method requirement 2021-02-09 00:09:46 -05:00
Robert Widmann
3790d5e277 [Gardening] overriden -> overridden 2021-02-08 11:22:57 -08:00
Slava Pestov
ed247a1fa1 Sema: Allow 'lazy' local variables 2021-02-06 08:56:38 -05:00
Slava Pestov
b053eae8fb Sema: Tweak assertion in CustomAttrTypeRequest to allow generic typealiases
If the typealias here is generic, we return an UnboundGenericType
where getAnyNominal() returns nullptr. This would fail by returning
an ErrorType to the caller without diagnosing anything.

This was a regression after some recent refactoring to remove code
duplication and some TypeLoc usages, because one of the copies of
this code did not have this check, so it happened to work for
property wrappers.

Relax the check by looking through a TypeAliasDecl explicitly.
I believe we can't end up here anyway, because if the type was
not a nominal we would fail earlier in CustomAttrNominalRequest, and
we wouldn't attempt to compute the type of the property wrapper at
all. However it's better to keep the assertion in place just in case.

Fixes https://bugs.swift.org/browse/SR-14143 / rdar://problem/73888684.
2021-02-02 23:10:38 -05:00
Robert Widmann
0009209cba Correct the Location of a Protocol Requirement Fixit
The old fixit mistakenly used getLoc() instead of getEndLoc() on the
type repr, which for simple identifiers will do the right thing. For
compound ones like `[T]`, it instead points inside of the repr inside
which leads to nonsensical fixes like [ { get }T]

rdar://73632764
2021-02-01 16:50:26 -08:00
Saidhon Orifov
cee0ba22f0 [DiagnosticsQol] Restore optionality in IUO redeclared functions (#34823)
* [DiagnosticsQol] Restore optionality in IUO redeclared functions

* [DiagnosticsQol] Rename redeclare err by optionality

* Add redecl note for optionals/IUOs

* Change redecl note wording: not different -> same

* Modify iuo redecl note

Co-authored-by: Saidhon Orifov <saidhon94@hotmail.com>
2021-02-01 11:29:36 -05:00
Doug Gregor
450bc77bea Merge pull request #35275 from DougGregor/looser-override-witness-isolation-objc 2021-01-30 18:47:11 -08:00
Doug Gregor
b7a86bb3bc Type check withoutActuallyEscaping on async functions
Fixes rdar://73695354.
2021-01-29 16:25:08 -08:00
Rintaro Ishizaki
ba23002716 Merge pull request #35567 from rintaro/parse-rdar73159041
[Parse] Diagnose default argument for subscript in protocols
2021-01-25 13:11:49 -08:00
Rintaro Ishizaki
8a58107123 [Parse] Diagnose default argument for subscript in protocols
Protocol requirements don't support default arguments. Although this is
a "semantic" diagnostics, we currently do this for 'func' and 'init' in
Parser. So for fixing a crash, let's to it for 'subscript' in Parser
too.

rdar://problem/73159041
2021-01-22 17:21:17 -08:00
Minhyuk Kim
5c21cdf4a6 Modify override_decl_extension error to be more descriptive 2021-01-23 01:04:40 +09:00
Varun Gandhi
b263e99d71 Merge pull request #35367 from mininny/simplify-unused-lvalue-wording
[Diagnostics] Simplify unused lvalue warning wording
2021-01-16 14:29:43 -08:00
Minhyuk Kim
7eaabe1996 Simplify unused lvalue warning wording 2021-01-15 22:14:56 +09:00
Slava Pestov
b18c7fb22b Sema: Allow re-declarations of typealiases in constrained extensions with different generic signatures
Associated type inference will synthesize typealiases in
constrained extensions for conditional conformances, but
then we might later flag them as re-declarations.

Let's not do this, since name lookup does check if generic
requirements are satisfied, so such redeclarations are not
in fact erroneous.

Fixes <rdar://problem/68933045>.
2021-01-13 21:59:27 -05:00
Slava Pestov
4337899ded Merge pull request #35334 from slavapestov/remove-evaluator-type-erasers
Remove request evaluator's AnyRequest and AnyValue type erasers
2021-01-11 14:44:54 -05:00
Doug Gregor
af948715d9 Fix test case 2021-01-11 09:00:27 -08:00
Slava Pestov
28e7ed03d0 AST: Remove the 'legacy' request dependency graph implementation 2021-01-08 23:17:12 -05:00
Slava Pestov
8117052a1e Sema: Tweak a diagnostic
We talk about 'protocol refinement' rather than 'protocol inheritance';
but in this case, a more specific phrase makes even more sense, I think.
2021-01-07 23:48:00 -05:00
Doug Gregor
f157c79a14 [Concurrency] Loosen isolation checking for overrides/witnesses to ObjC.
When overriding a method or witnessing a requirement that comes from
Objective-C and has no actor annotation, allow the overriding method
or witness to specify a global actor (any global actor, but probably
almost always the main actor) without triggering the actor-isolation
errors one would normally get if both entities were written in Swift.

This opens up a hole in actor-isolation checking, because nothing
guarantees that code won't call these methods through the superclass
or protocol from the wrong actor. On the other hand, it's a very
convenient hole, because it allows us to state when we "know" that an
Objective-C framework will only call a method on (e.g.) the main
actor, and make that known to Swift to be enforced everywhere else in
Swift. If this is a good idea, it's plausible to introduce runtime
assertions of some form to tell the user when such an annotation is
wrong.
2021-01-05 22:20:26 -08:00
Doug Gregor
3c38ffe0ea [Concurrency] await try -> try await
The `try await` ordering is both easier to read and indicates the order
of operations better, because the suspension point occurs first and
then one can observe a thrown error.
2020-12-23 13:21:59 -08:00
Evan Wilde
1d53d748d3 Cleanup actor protocol conformance error
This patch cleans up how we emit the errors for disallowing the
properties and methods of an actor to be applied to the protocol
conformance. Rather than having multiple error messages for each case,
we keep one error message saying that the actor-isolated
method/variable/what-have-you cannot be used to satisfy a protocol
requirement, then allow multiple notes with fix-its to allow the
programmer to choose what they want to do. The notes have a better
description of what each option does.
2020-12-17 16:12:41 -08:00
Pavel Yaskevich
ec31d77fa6 [Diagnostics] Allow integer cast fix-its for assignment mismatches 2020-12-11 20:49:54 -08:00
Luciano Almeida
d954b840fd [tests] Adjusting SR-11535 test case on the suit 2020-12-05 22:48:09 -03:00
Luciano Almeida
cba7029329 [NFC] Correcting test case for SR-11535 and adding a explanation comment 2020-12-05 22:48:09 -03:00
Doug Gregor
dd7ce8015d [Concurrency] Reject top-level asynchronous code for now.
We haven't implemented any support for top-level async code yet, so
reject it in effects checking rather than crashing in the SIL verifier.
Fixes rdar://71512818.
2020-12-03 22:28:58 -08:00
Doug Gregor
3530dc6d8d [Concurrency] Allow synchronous witnesses to satisfy 'async' requirements. 2020-12-03 16:44:32 -08:00
Doug Gregor
1798e66c6e [Concurrency] Disallow 'async' and non-async overloading. 2020-12-03 09:34:15 -08:00
Luciano Almeida
3e386550bf Merge pull request #34883 from LucianoPAlmeida/SR-13899-coerce-to-checked
[SR-13899] [Sema] Adjustments on coerce to checked cast diagnostics
2020-12-01 21:30:28 -03:00
Luciano Almeida
158bf61359 [test] Adding specific tests for the warning for protocol inheritance class keyword syntax deprecation 2020-11-29 21:44:03 -03:00