Commit Graph

1081 Commits

Author SHA1 Message Date
Doug Gregor
64cb042a76 [Type checker] Allow the ‘override’ keyword on protocol members. 2018-09-04 16:42:06 -07:00
Doug Gregor
438d2606e6 [Override checking] Check property types correctly for protocol overrides. 2018-09-04 16:42:06 -07:00
Doug Gregor
0972111c60 [Type checker] Start tracking overrides of protocol requirements.
When a protocol that inherits another protocol restates a requirement
from its inherited protocol, track that as an override in the AST.
2018-09-04 16:42:06 -07:00
Matt Diephouse
5e9da14b5a Pare down operator candidates during protocol type checking 2018-08-28 08:41:15 -04:00
Hamish Knight
819a13e880 [GSB] Avoid emitting associated type diagnostics on the protocol decl
For explicit abstract protocol floating requirement sources, get the source location from the protocol requirement rather than delegating to the parent `RequirementSource`.
2018-08-27 18:39:04 +01:00
Doug Gregor
e67d78d919 Update test case for better recursion detection. 2018-08-20 23:59:30 -07:00
Doug Gregor
8d11ce1028 Minor test case update due to cycle detection. 2018-08-14 02:19:21 -07:00
Doug Gregor
b947a47a5d [AST] Reimplement ProtocolDecl::getInheritedProtocols() on decl name lookup.
Use the declaration-based name lookup facilities to re-implement
ProtocolDecl::getInheritedProtocols(), rather than dynamically selecting
between the requirement signature and the inherited types. This reduces
dependencies for this computation down to basic name lookup (no semantic
analysis) and gives us a stable result.
2018-08-06 16:12:09 -07:00
Slava Pestov
3454a54ee3 Sema: Move checkProtocolSelfRequirements() and checkReferencedGenericParams() to typeCheckDecl()
Checking these in a code path called from validateDecl() is overkill;
it's sufficient to perform these checks in declarations in primary files
only.
2018-07-31 02:08:37 -07:00
Mark Lacey
78d83e5703 Use %target-typecheck-verify-swift where possible. 2018-07-26 23:13:43 -07:00
Doug Gregor
6a8d3211aa [Type checker] Move ad-hoc isObjC/isDynamic checking to finalization.
Whenever we visit a declaration via the DeclChecker, add it to the
list of declarations to finalize. This makes sure that we can centralize
the notion of “finalize for SILGen” and that it will be called for
everything in the source file being processed.
2018-07-25 20:55:13 -07:00
Slava Pestov
eeb5c953aa Sema: Ban protocol where clauses that place constraints on 'Self'
These will never work properly because of phase ordering issues with
the current declaration checker design. Since we can always express
the same thing with the protocol inheritance clause instead, just
diagnose this as an error instead of trying to hack around it.

Fixes <rdar://problem/38077232>, <https://bugs.swift.org/browse/SR-5581>.
2018-07-10 00:34:02 -07:00
Slava Pestov
323b70c1cb Sema: @objc protocols cannot have a superclass constraint 2018-07-09 23:56:25 -07:00
Slava Pestov
3937732b9b Add more tests for protocols with superclass 2018-07-09 23:56:25 -07:00
Slava Pestov
cb4a248e6b Sema: Diagnose non-required class initializer calls on protocols with superclass contraint 2018-07-06 23:39:39 -07:00
Slava Pestov
66e6a6a2c5 AST: Fix name lookup for protocols with superclasses
Also, start adding some tests now that basic things seem to work.
2018-07-06 23:39:39 -07:00
Slava Pestov
19a37c8a83 Sema: Fix source compatibility break from relaxed witness matching rules
This is fix for a source compat regression from:

commit 790625ab5b
Author: Doug Gregor <dgregor@apple.com>
Date:   Mon Mar 19 15:29:32 2018 -0700

    Allow a witness's noescape parameter to match a requirement's escaping parameter

The regression is not severe but its easy enough to fix.

With the above change, it was possible for an optional requirement that did
not have a witness in Swift 4.1 to pick up a witness in Swift 4.2, because
the escaping/noescape mismatch prevented it from being considered in Swift 4.1.

If the new witness was not sufficiently visible, this caused a source
compatibility regression.

Work around this by discarding the witness if its not sufficiently
visible. In -swift-version 5, the hack expires, and we revert to the
stricter, more consistent behavior.

Fixes <rdar://problem/39614880>.
2018-07-04 00:30:36 -07:00
Jordan Rose
9ee996cf82 Eagerly create init(from:) when looking up 'init' on a Decodable type (#17712)
Otherwise, the initializer won't be inherited properly onto a
subclass, resulting in the base class being allocated instead of the
subclass when using Sub.init(from:).

https://bugs.swift.org/browse/SR-8083
2018-07-03 18:09:09 -07:00
Slava Pestov
9ec1926731 Sema: Allow classes in protocol inheritance clauses 2018-07-02 22:06:33 -07:00
Slava Pestov
94f175fcad Sema: Remove redundant protocol circularity check 2018-07-02 22:06:33 -07:00
Slava Pestov
31ab93b82c Remove Swift 3-specific tests 2018-07-02 21:14:22 -07:00
Slava Pestov
ba30de0f08 Sema: Re-word circular inheritance diagnostics 2018-06-28 16:54:28 -07:00
Slava Pestov
3701f745c4 Migrate various Sema tests to Swift 4 2018-06-25 01:02:20 -07:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Robert Widmann
9bd02e1d17 Allow eliding ownership conventions in a copyable context
Allow witnesses to protocols in a copyable context to elide explicit
ownership conventions.  This allows clients like the standard library to
standardize on one ownership convention without an ABI or API breaking
change in 3rd party code.

In the future, moveonly contexts must disallow this default behavior
else the witness thunks could silently transfer ownership.

rdar://40774922

protocol P {
  __consuming func implicit(x: __shared String)
  __consuming func explicit(x: __owned String)
  __consuming func mismatch(x: __shared String)
}

class C : P {
  // C.implicit(x:) takes self and x '@guaranteed' thru the witness thunk
  func implicit(x: String) {}
  // C.explicit(x:) takes self and x @owned with no convention changes
  __consuming func explicit(x: __owned String) {}
  // Would inherit __consuming, but x has been spelled __owned so the requirement match fails.
  func mismatch(x: __owned String) {}
}
2018-06-19 12:25:50 -07:00
Doug Gregor
18569e5f77 Merge pull request #16963 from DougGregor/evaluator-type-checker
[Type checker] Use the request-evaluator in the type checker.
2018-06-15 22:41:31 -07:00
Matt Diephouse
87aaf10e6b [Diagnostics] Improve error when type parameters aren't equal 2018-06-15 15:08:05 -04:00
Doug Gregor
ebd774bcd1 [Sema] Eliminate the last use of the IterativeTypeChecker.
Implement TypeChecker::resolveInheritedProtocols() in terms of
"getInheritedType()" queries, instead.

[Sema] Put back resolveInheritedProtocols().

We're still depending on it to update state in some cases.
2018-06-14 15:29:57 -07:00
Doug Gregor
2b2e143f59 [Request-Evaluator] Introduce a request for getting an "inherited type". 2018-06-14 15:29:57 -07:00
Ben Langmuir
b0aeae4a78 Merge pull request #16682 from bdash/ast-dump-source-ranges
Include source ranges for statements, declarations, and parameter lists in the AST dump
2018-05-23 10:54:03 -07:00
Itai Ferber
fc8f6824f7 Typo fix in Codable test comment 2018-05-21 07:54:17 -07:00
Mark Rowe
62eb12b652 Include source ranges for decls in the AST dump. 2018-05-17 10:50:19 -07:00
Ben Langmuir
f20586b3d8 Revert "Include source ranges for statements, declarations, and parameter lists in the AST dump" 2018-05-17 09:53:05 -07:00
Jordan Rose
cb6c8f0a8e Merge pull request #16473 from bdash/ast-dump-source-ranges
Include source ranges for statements, declarations, and parameter lists in the AST dump
2018-05-17 09:16:35 -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
Mark Rowe
28af6959b8 Include source ranges for decls in the AST dump. 2018-05-09 11:15:35 -07:00
Huon Wilson
19d785018c [Sema] Use the conformance decl in more diagnostics/validity checks in conformance synthesis. 2018-05-09 09:55:41 +10:00
Huon Wilson
fe7240ab8a [Sema] Disallow synthesis-in-extensions in Swift 3.
'private' properties can't be accessed in extensions in Swift 3, so synthesizing
a conformance that reads from such things is going to be incorrect in an
extension.
2018-05-09 09:55:41 +10:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Huon Wilson
27d8f17b44 [Sema] Fix synthesis of *codable conformances in extensions of generic types.
Fixes https://bugs.swift.org/browse/SR-6803 and rdar://problem/39199726.
2018-05-07 09:44:38 +10:00
Huon Wilson
3488a3a53b [Sema] Allow synthesis of protocol conformances in extensions.
This works for all protocols except for Decodable on non-final classes, because
the init requirement has to be 'required' and thus in the type's declaration.

Fixes most of https://bugs.swift.org/browse/SR-6803.
2018-05-07 09:41:25 +10:00
Huon Wilson
59bcbb3b41 Merge pull request #16201 from huonw/overlapping-conditional-conformances
[Sema] Diagnose redundant conditional conformances more specifically.
2018-04-30 11:07:10 +10:00
Huon Wilson
2e5799e26b [Sema] Diagnose redundant conditional conformances more specifically.
We don't allow things like

    extension Type: P where Param: P {}
    extension Type: P where Param: Q {}

or

    extension Type: P where Param == Int {}
    extension Type: P where Param == Float {}

or

    extension Type: P where Param: P {}
    extension Type: P where Param == SomethingThatIsntP {}

and the default error message "redundant conformance" message doesn't convey
this very well.

Fixes rdar://problem/36262409.
2018-04-27 11:50:17 +10:00
Michael Gottesman
3d990e98d2 [codable] When generated encode for a property, distinguish in between static/instance properties.
Previously, we just took the first match so:

1. We would try to emit a metatype lookup of the property but had prepared an instance lookup.
2. Could get the wrong type if the static/instance property had different types.

rdar://39669212
2018-04-24 15:57:47 -07:00
David Zarzycki
bfda039f8c [Diag] QoI: ownership in protocol check should not be 'else' clause (#16093) 2018-04-23 09:52:38 -04:00
David Zarzycki
e326954bd0 [Diag] QoI: Add ReferenceOwnership to DiagnosticArgumentKind
By formalizing ReferenceOwnership as a diagnostic argument kind, we get
less boilerplate, better type safety, better output consistency, and
last but not least: future proofing.
2018-04-20 08:32:43 -04:00
Slava Pestov
03bdbed0d9 Sema: Diagnose missing class initializers late
This gives us a chance to synthesize the init(from:).

Fixes <https://bugs.swift.org/browse/SR-7315>, <rdar://problem/39102390>.
2018-04-19 18:22:34 -07:00
swift-ci
335b0299c8 Merge pull request #15859 from itaiferber/codingkey-validation-invalid-typealias 2018-04-18 18:33:37 -07:00
Jordan Rose
28a1dc7770 Use 'fileprivate' for synthesized members of 'private' decls (#15980)
Since 'private' means "limit to the enclosing scope (and extensions
thereof)", putting it on a member means that the member can't be
accessed everywhere the type might show up. That's normally a good
thing, but it's not the desired effect for synthesized members used
for derived conformances, and when it comes to class initializers this
actually violates AST invariants.

rdar://problem/39478298
2018-04-17 15:19:35 -07:00