Commit Graph

9116 Commits

Author SHA1 Message Date
Robert Widmann
82b13d11ac Merge pull request #10784 from CodaFi/my-sweet-noescape
[SR-5296] @autoclosure and @noescape are not decl attributes
2017-07-06 00:01:21 -07:00
Robert Widmann
b8069fbd8d Update tests to remove @autoclosure in decl position
Also restore some diagnostics in TypeCheckType that should have
migrated with the attributes.  In particular, diagnose cases where
we have @autoclosure with any function type repr with a non-Void
input type.

Resolves SR-5296
2017-07-05 22:09:19 -07:00
Robert Widmann
ab580a3a0a Remove @autoclosure and @noescape as decl attributes
Using these in declaration position has been deprecated and
removed in Swift 3.  These attributes were not being parsed and
contained deadweight diagnostics that should have been moved
when these attributes became type attributes.
2017-07-05 21:27:04 -07:00
Joe Groff
2bb827340b Sema: Simplifying a KeyPathExpr's type should *bind* to the specific type, not accept a subtype constraint.
We want the type of a KeyPathExpr to be the specific *KeyPath<T, U> subclass appropriate for the literal, with upcasts to a more general contextual type, since we rely on that invariant elsewhere to extract the base and projected value types. Fixes SR-5008 | rdar://problem/32395076.
2017-07-05 19:15:45 -07:00
Pavel Yaskevich
c45073efd1 [QoI] Don't try to lookup members on incorrect type while diagnosing keypath components
While trying to diagnose problems related to keypath components
don't assume that type of the component is always correct, check
before trying to see if it's bridged type or has members.

Resolves: rdar://problem/33135487
2017-07-05 17:19:05 -07:00
Robert Widmann
f11779572c Replace setLet with setSpecifier 2017-07-05 14:41:59 -07:00
Robert Widmann
4da853e7cb Rename Specifier::None to Specifier::Owned 2017-07-05 14:02:26 -07:00
Robert Widmann
e423d8c0b2 Remove duplicated conveniences 2017-07-05 14:01:07 -07:00
Jordan Rose
88556eec94 Avoid building conformance lookup tables when we don't have to.
- Deinitializers never get a custom Objective-C name.
- Classes and protocols are never bridged themselves; that only matters
  for structs and enums.

This avoids another circularity issue like the one in a8bc132565,
where the Clang importer ends up importing a class and hands it to the
type checker, which then asks about conformances. The conformance
lookup table goes to add the extension from the Swift module, except
that the Swift module is what asked for the import in the first place.

It's possible there's a more general solution here, but this
particular change is good even in the non-crashy cases, and definitely
safe for Swift 4.0. Even if the test case is even more idiosyncratic
than the last one.

The test case change for SourceKit is probably due to the first
category not triggering the import of the other two
categories. Changes in import order have been known to affect source
compatibility, though not frequently. However, categories are not
intended to be ordered in the first place. There's still more we can
do in this space, and implicitly depending on these calls /outside/ of
the importer to control category import order was quite brittle
anyway.

SR-5330 / rdar://problem/32677610
2017-07-05 11:23:27 -07:00
Pavel Yaskevich
45bfefbe39 Merge pull request #10672 from d-ronnqvist/SR-4715
[QoI] Handle out of order arguments by reordering them
2017-07-02 12:34:46 -07:00
David Rönnqvist
00833a2343 [QoI] Improve the fix-it for out-of-order arguments.
Change the fix-it to move the argument to its correct location in one go. This happens by removing it from one location and inserting it in the other (as opposed to the original implementation which swapped one argument with the preceding one). The commas separating the arguments are adjusted to match the moved argument.

Add new tests for reordering regular arguments, variadic arguments, and function arguments.

Resolves: SR-4715 rdar://problem/31849281
2017-07-02 10:15:18 +02:00
Alex Hoppen
f35f29d9cf [Diag] Change function diagnostics to take a DeclName parameter
This provides richer error messages that include the function's
parameters
2017-07-01 13:37:08 +02:00
Alex Hoppen
0b286151cc [Diag] Diagnostic adjustment for special DeclNames
The diagnostic warn_unqualified_access cannot exist with special
DeclNames and shall thus take an Identifier as parameter
2017-07-01 13:29:02 +02:00
swift-ci
cb38983f86 Merge pull request #10742 from DougGregor/gsb-no-longer-gross 2017-06-30 22:12:29 -07:00
swift-ci
3e31e8c2cd Merge pull request #10721 from CodaFi/parampa-tha-rappa 2017-06-30 10:50:08 -07:00
Robert Widmann
4411223156 [NFC] Switch some more of the frontend to params 2017-06-30 10:24:52 -07:00
Doug Gregor
ae5091b09a [GSB] Clean up and audit uses of ArchetypeResolutionKind.
Use ArchetypeResolutionKind::CompleteWellFormed whenever we need to
ask questions about the potential archetype, and
ArchetypeResolutionKind::WellFormed when we need only evaluate whether
there is a legitimate type with that name (and possibly get a handle
to it).
2017-06-30 10:05:12 -07:00
swift-ci
c063d4939f Merge pull request #10714 from DougGregor/gsb-no-unresolved-potential-archetypes 2017-06-30 09:51:18 -07:00
Doug Gregor
dbc042261f [Type checker] Ensure we validate type declarations before using them.
Fixes a crasher regression.
2017-06-30 09:30:43 -07:00
Pavel Yaskevich
a82b16fb2d [QoI] Don't assume that contextual type is always present for trailing closure diagnostics
Fixes crasher in diagnostics related to the fact that contextual type
is not always available when trying to diagnose problems related to
calls with trailing closures.

Resolves: rdar://problem/33067102
2017-06-29 23:09:55 -07:00
Robert Widmann
679584d8d8 Merge pull request #10695 from CodaFi/all-specd-out
[NFC] Use a meaningful representation of parameter specifiers
2017-06-29 20:00:14 -07:00
Robert Widmann
e4fbb381aa Merge pull request #10710 from practicalswift/typos-20170629
[gardening] Fix typos
2017-06-29 18:03:56 -07:00
Doug Gregor
e3b09f3850 [GSB] Remove typo correction. NFC
Remove typo correction and all notions of "renamed" potential
archetypes from the generic signature builder. They're no longer used
anywhere.
2017-06-29 16:52:46 -07:00
Doug Gregor
ac8e8aa1b3 [GSB] Stop creating unresolved potential archetypes; rework typo correction.
The small-but-significant change to the generic signature builder is
to refuse to create unresolved potential archetypes. Instead, delay
any requirement that depends on such type, to be reprocessed once
we've seen all of the other requirements. If the type can be resolved
later, it will be; Otherwise, the type checker will complain when it
sees an unresolvable type. By itself, this fixes the crash in SR-2796.

Doing this by itself regresses diagnostics because typo correction in
the generic signature builder no longer kicks in. Therefore, implement
typo correction for these cases in the type checker proper, using its
existing facilities for typo correction. The result is more consistent
code with a better result.

Fixes SR-2796 / rdar://problem/28544316.
2017-06-29 16:52:46 -07:00
Robert Widmann
ac5594dabe Use a meaningful representation of parameter specifiers
In anticipation of future attributes, and perhaps the ability to
declare lvalues with specifiers other than 'let' and 'var', expand
the "isLet" bit into a more general "specifier" field.
2017-06-29 16:03:49 -07:00
swift-ci
97f2f8bf2b Merge pull request #10711 from DougGregor/requirement-signature-improvements 2017-06-29 15:00:40 -07:00
practicalswift
d39719ec3f [gardening] Fix typos 2017-06-29 23:09:22 +02:00
Doug Gregor
623d72db3c [AST] Make the "requirement signature" of a protocol a flat array.
Rather than pretend that the requirement signature of a protocol is a
full, well-formed generic signature that one can meaningfully query,
treat it as a flat set of requirements. Nearly all clients already did
this, but make it official. NFC
2017-06-29 14:01:49 -07:00
Robert Widmann
43f29399f3 Remove an old diagnostic for 'var' in param position
Using the attribute in this position is a relic from the Swift 2
days, and fixing it required letting invalid code fall through to
Sema instead of being diagnosed in Parse proper.  Treat 'var'
in this position like 'let' by simply offering to remove it
instead of extracting it into a separate variable.
2017-06-29 13:35:59 -07:00
swift-ci
a0acfd62b6 Merge pull request #10696 from xedin/rdar-32241441 2017-06-28 23:21:21 -07:00
Pavel Yaskevich
5f57183654 [QoI] Add fix-it for cases in switch with optional chaining
When type-checking switch statements with patterns let's
check if we have an optional type and try to see if the case
exists in its base type, if so we can suggest a fix-it.

Resolves: rdar://problem/32241441
2017-06-28 22:20:55 -07:00
swift-ci
69f712708a Merge pull request #10688 from DougGregor/requirement-sig-first 2017-06-28 16:36:40 -07:00
Doug Gregor
158c048149 [Type checker] Always compute protocol requirement signature first.
The protocol requirement signature is key to conformance access paths
and other queries related to protocols. Make sure we create it first.
2017-06-28 13:55:46 -07:00
Pavel Yaskevich
ef55d42334 [QoI] Emit shadowing diagnostics even if argument types do not much completely
Relax restriction placed on the function shadowing diagnostics
and allow such diagnostics to be emitted even when argument types
do not match expected parameter types, but use "near match" message
in that case to clarify that shadowing is not exact.

Resolves: rdar://problem/32854314
2017-06-28 13:35:26 -07:00
Robert Widmann
d07eb71d9c Merge pull request #9457 from rintaro/parse-ifconfig-switchcase
[Parse] Allow #if to guard switch case clauses
2017-06-28 10:18:37 -07:00
Doug Gregor
cb93331f66 [GSB] Distinguish archetype resolution kind for getNestedType().
PotentiallArchetype::getNestedType(Identifier...) was using
ArchetypeResolutionKind::AlwaysPartial, even though only one client
(the code that itself handles AlwaysPartial) needed it. Add an
ArchetypeResolutionKind parameter to pass through, updating clients
accordingly.

Eliminates 5 effective uses of AlwaysPartial. Only two left!
2017-06-28 09:41:06 -07:00
Robert Widmann
d27ed5a9ec Include Editor Mode when downgrading exhaustiveness error to warning 2017-06-28 00:27:43 -07:00
Pavel Yaskevich
1ffac2e651 [QoI] Improve diagnostics related to member calls
When trying to diagnose problems related to calls where
function is represented by a member of nominal type let's
attempt to be more cautious while type-checking function
expression without it's arguments, because it could produce
unrelated diagnostics.

Resolves: rdar://problem/32551313, rdar://problem/28456467, rdar://problem/31671195
2017-06-27 15:49:11 -07:00
swift-ci
a35bbf0656 Merge pull request #10630 from DougGregor/record-conformance-in-source-file 2017-06-27 11:10:59 -07:00
Harlan
e89e7f58b2 [Parse] [Syntax] Simplify TupleTypeRepr parsing and add attributes for Syntax (#8298)
* Simplify TupleTypeRepr parsing

This patch introduces a TupleTypeReprElement struct that holds the
locations for all relevant bits of tuple elements. It removes the
NameLoc and UnderscoreLoc arrays from TupleTypeReprElement in favor of
holding each of these on TupleTypeReprElement. These extra bits of info
are required for full-fidelity representation in the Syntax library.

* Remove TupleTypeReprBitfields and move EllipsisLoc out of TrailingObjects

* Update users of TupleTypeRepr

* Don't resize the elts if we're going to push_back

* getType -> getElementType

* Move ellipsis back into TrailingObjects.

* Move NumElements into TupleTypeReprBitfields
2017-06-27 10:54:47 -07:00
Doug Gregor
82463675e2 [Type checker] Always record used conformances in the source file.
An early exit introduced in PR #10292 meant that we would only record
a protocol conformance as "used" in the first file in which we saw a
reference to the conformance. Make sure we record the conformance as
used in each source file that needs it. Fixes rdar://problem/32978891
and rdar://problem/32980176.
2017-06-27 09:57:00 -07:00
Robert Widmann
d0b4969e3c Remove a redundant input type destructuring primitive 2017-06-27 00:42:33 -07:00
Joe Groff
d07441651f Merge pull request #10556 from jckarter/key-path-optionals
KeyPaths: Add support for optional chaining/forcing components.
2017-06-26 18:57:42 -04:00
swift-ci
f9b2047cc0 Merge pull request #10571 from xedin/sr-5045 2017-06-26 14:08:42 -07:00
Pavel Yaskevich
4e6677e7c4 [QoI] Improve contextual error diagnostics related to calls
Currently some contextual errors are discovered too late
which leads to diagnostics of unrelated problems like argument
mismatches, these changes attempt to improve the situation
and try to diagnose contextual errors related to calls
before everything else.

Resolves: SR-5045, rdar://problem/32934129
2017-06-26 13:12:32 -07:00
Joe Groff
3c82e981f9 KeyPaths: Add support for optional chaining/forcing components.
rdar://problem/31768715
2017-06-26 09:40:31 -07:00
Alex Hoppen
949968a182 Adjust printing to take into account special DeclNames
Print DeclBaseNames using a new userFacingStr() method to prepare for
DeclBaseNames that are not backed by Identifiers
2017-06-24 11:39:09 +02:00
swift-ci
06da599aff Merge pull request #10527 from harlanhaskins/🔥🌲🔥 2017-06-23 15:34:10 -07:00
Mark Lacey
c68daab338 Merge pull request #10531 from rudkx/fix-rdar32618740
[Constraint solver] Gather constraints from adjacencies of equiv class.
2017-06-23 11:59:08 -07:00
Mark Lacey
687624e317 [Constraint solver] Gather constraints from adjacencies of equiv class.
When gathering constraints for a type variable, we were gathering all of
the constraints for the members of the equivalence class, and then for
the adjacencies of the representative of the equivalence class, but not
from the adjacencies of other members of the equivalence class.

For example for:
  #3 = $T3
  #4 = $T4 equivalent to $T3
  #5 = $T5 as $T4.Element

after binding $T3 we would collect the constraints related to $T3 and
$T4, but not $T5. The end result can be that we finish examining all
disjunctions and type bindings but still have inactive constraints in
the constraint graph, which is treated as a failure in the solver.

Fixes SR-5120 / rdar://problem/32618740.
2017-06-23 09:43:06 -07:00