Commit Graph

7976 Commits

Author SHA1 Message Date
Jordan Rose
a14e3291ce Say "ambiguous use of 'foo'" instead of "'foo(bar:)'".
...unless the argument labels are the same for every possible
overload.

Only affects diagnostics.
2016-09-15 10:38:44 -07:00
Doug Gregor
4c45885ffd [Name lookup] Diagnose attempts to reference not-yet-declared local variables.
Until the point where ASTScope-based unqualified name lookup is the
default, unqualified name lookup can still find names declared *after*
the source location. The 'hasType' check no longer makes sense, so actually
check the source location of the entity we found.
2016-09-15 10:21:30 -07:00
Doug Gregor
c6bd5c7ca1 [Type checker] Validate not-yet-typed declarations we find via unqualified name lookup.
When using the ASTScope-based unqualified name lookup, we might find
things that are in scope but haven't been fully type-checked yet;
allow us to perform type checking.
2016-09-15 09:16:46 -07:00
Doug Gregor
ac93c52c96 [Scope map] A local property name is in scope within its own accessors.
While the use of a local property from within its own accessors is a
bit dubious, Swift 3 only warned on it, so model the existing lookup
behavior in the scope map.
2016-09-15 09:16:46 -07:00
Doug Gregor
e9f3fb0314 Merge pull request #4775 from xedin/dpc-improvements-fix
[Type Checker] Extend Path Consistency algorithm to cover collections
2016-09-14 22:34:52 -07:00
Slava Pestov
888a32be60 Merge pull request #4758 from slavapestov/small-generics-cleanups
Small generics cleanups
2016-09-14 15:53:33 -07:00
Pavel Yaskevich
73318a2132 [Type Checker] Extend Path Consistency algorithm to cover collections
ExprCollector is extended to cover all generic collections instead of
only dictionary expressions. Contextual type propagation is extended
to support partial solving of collections embedded into coerce expressions.
2016-09-14 13:51:08 -07:00
swift-ci
c1ec0cad06 Merge pull request #4766 from eeckstein/revert-tc 2016-09-14 12:24:00 -07:00
practicalswift
9185c052a9 [gardening] Fix inconsistent headers 2016-09-14 20:48:28 +02:00
Erik Eckstein
38cb48b29a Revert "[Type Checker] Extend Path Consistency algorithm to cover collections"
This reverts commit f590a1ba03.

It breaks this kind of code:

test.swift:2:34: error: cannot convert value of type 'Int' to expected element type 'UInt32'
 let lengthBytes: [UInt32] = [55 * 8, 0]
                              ~~~^~~
                              UInt32( )
2016-09-14 11:15:34 -07:00
Doug Gregor
6b91c5bb34 [Type checker] Handle explicit conversion of bridged generic types.
The type checker had some logic for performing specific checking for
explicit bridging casts of generic types based on knowledge of
Array/Dictionary/Set, but pretended no other bridged generic types
existed. That's incorrect now; simply require them to match exactly.

Fixes rdar://problem/27539951.
2016-09-14 11:00:30 -07:00
Slava Pestov
132a47105c Sema: Minor fixes 2016-09-13 22:58:59 -07:00
Slava Pestov
aaf016c645 AST: Remove ArchetypeType::isSelfDerived() 2016-09-13 22:58:59 -07:00
Pavel Yaskevich
f590a1ba03 [Type Checker] Extend Path Consistency algorithm to cover collections
ExprCollector is extended to cover all generic collections instead of
only dictionary expressions. Contextual type propagation is extended
to support partial solving of collections embedded into coerce expressions.
2016-09-13 01:34:14 -07:00
Pavel Yaskevich
99ac807e9e [Type Checker] replace std::{stack, queue} with llvm::SmallVector 2016-09-13 00:37:40 -07:00
Robert Widmann
38116d4896 Merge pull request #4705 from CodaFi/you-cant-have-a-con-version-without-the-confidence
Don't attempt a value conversion without a valid conversion pair
2016-09-12 22:07:47 -04:00
Jordan Rose
9e79e0b362 Provide a fix-it when overriding 'Any' with 'AnyObject'. (#4729)
This helps when manually migrating Swift 2 code to Swift 3, which
includes SE-0116 (id-as-Any). We already did this for specific bridged
types (like URL and NSURL); this just adds a special case for
Any/AnyObject.

rdar://problem/27865590
2016-09-12 17:19:53 -07:00
Robert Widmann
ff2289d77a Don't attempt a value conversion without a valid conversion pair
Previously this would crash when invalid tuple conversions were
encountered because we would try to convert NULL Expr nodes.
2016-09-12 11:27:57 -04:00
Rintaro Ishizaki
339387e95b [AST] Remove DefaultValueExpr type (#4713)
The last instantiation of this type was removed in 68bcb0d2af
2016-09-12 16:50:02 +09:00
Mishal Shah
10ca65aac8 Merge pull request #4684 from milseman/escaping
[noescape-by-default] Diagnostic notes for closure type arguments
2016-09-09 15:47:39 -07:00
Mishal Shah
9bb7644a69 Merge pull request #4419 from milseman/no_factory
[Import as Member] Error on convenience inits in extensions of CFTypes
2016-09-09 14:28:28 -07:00
Michael Ilseman
ffd3dde01c [TypeChecker] Don't double validate dict types
Prior, binding generic args in dictionary type checking would double
resolve the key and value types a second time, emitting duplicated
errors potentially. Instead, we reuse the resolved types.
2016-09-09 13:00:21 -07:00
Michael Ilseman
585716387c [noescape-by-default] Diagnostic notes for closure type arguments
Adds in helpful notes when a closure type argument is already
escaping, and thus doesn't need annotation. The common case targeted
now is Optional and IUO, which is the biggest bang for our buck
without needlessly complicating the type options.

Test cases included for the new note, and potential interactions.

In the future we'd like some kind of parent pointer, or context stack
to give better diagnostics universally. For now, we hack it by having
ImmediateOptionalTypeArgument as a special flag.
2016-09-09 13:00:21 -07:00
John McCall
0bdc8b2a3b Merge pull request #4689 from rjmccall/optional-abstraction
Abstract the object type of optional types
2016-09-09 10:19:36 -07:00
John McCall
34fb15e375 Abstract the object type of an optional type according to the
abstraction pattern of the type rather than always using the
most-general pattern, and erase ImplicitlyUnwrappedOptional from
the SIL type system.
2016-09-08 23:26:19 -07:00
Slava Pestov
b677a2e6a7 AST: Use the new Type::subst() in a few places
SILType substitutions are still done with the old form, and until
BoundGenericTypes hold conformances, we still have to pass around
a ModuleDecl in a few places we really shouldn't, but one step
at a time.
2016-09-08 21:59:13 -07:00
Slava Pestov
a993e36c06 AST: Add a new SubstitutionMap data structure
This replaces the TypeSubstitutionMap / ConformanceMap pair that
has been appearing more and more lately.
2016-09-08 21:59:11 -07:00
swift-ci
3525584cdd Merge pull request #4676 from DougGregor/astscope-lazy-initializers 2016-09-08 12:46:01 -07:00
Doug Gregor
67bf68ae70 [Name lookup] Support lookup of 'self' in lazy property initializers.
Lazy property initializers can refer to 'self' either directly or
implicitly (via references to instance members). Model this in
ASTScope-based unqualified name lookup.

Note that the modeling of 'self' with the current name lookup
mechanism is broken, so when ASTScope-based unqualified name lookup is
enabled, it fixes SR-2203, rdar://problem/16954496, and the many dupes
of the latter.
2016-09-08 11:24:03 -07:00
swift-ci
816b316f81 Merge pull request #4671 from DougGregor/scope-map-fixes 2016-09-07 21:13:48 -07:00
Doug Gregor
abf9bfe9d5 [Scope map] Provide scopes for the generic parameters of protocols and extensions. 2016-09-07 16:44:36 -07:00
Michael Ilseman
c16f8919d8 [escaping] Correct diagnostic for parameter position
In situations where @escaping is used in non-function-parameter
positions, we give an incorrect diagnostic message pertaining to
function types. Instead, we should just state that this is not allowed
in non-function-parameter positions.

This includes the general message fix. Unfortunately, this does not
include more friendly messages for special cases, e.g. closure members
of aggregate and optional closures. That may be possible with more
nested type context information in TypeCheckType.
2016-09-07 15:38:20 -07:00
Jordan Rose
c85ea1fc81 Merge pull request #4654 from jrose-apple/testable-protocol-witnesses
Allow @testable witnesses to satisfy protocol requirements.

rdar://problem/28173654
2016-09-07 13:36:53 -07:00
Doug Gregor
4820453820 [Type checker] Minor cleanups for @objc inference from witnesses. 2016-09-06 20:59:57 -07:00
swift-ci
8358d3ce80 Merge pull request #4651 from DougGregor/throwing-objc-inference 2016-09-06 17:55:52 -07:00
Jordan Rose
c6a79209f7 Allow @testable witnesses to satisfy protocol requirements.
That is, if a would-be witness to a protocol requirement is only
accessible because its module has been imported with '@testable',
consider that "good enough" to satisfy the rule that a witness
must be available everywhere the protocol and conforming type are
both available (because those other contexts /could/ have done their
own testable import).

rdar://problem/28173654
2016-09-06 17:10:28 -07:00
swift-ci
27ac660f6c Merge pull request #4648 from DougGregor/infer-objc-superclasses 2016-09-06 16:40:27 -07:00
Doug Gregor
cba7eb960d [Type checker] Throwing methods must return an object type in the @objc thunk to be @objc.
A throwing method can only be exposed to Objective-C if we can map the
return type convention, either because the return type is Void or
because it is something that is bridged to an object type (and can
therefore be nil to indicate error). Our predicate for checking
"bridged to an object type" didn't account for value types that are
exposed to (or come from) C, and therefore aren't actually bridged to
object types in the Objective-C thunk, meaning they cannot be
optional. An existing hack dealt with the largest class of
these---types like Int and Bool that can be dynamically bridged
to NSNumber---but generalize this by checking exactly how the result
type is going to be represented in Objective-C, rejecting '@objc' for
cases where the result type won't be an object type.

Fixes rdar://problem/28035614 for real.
2016-09-06 16:25:46 -07:00
Doug Gregor
7e3c13cb27 [Type checker] Infer @objc for witnesses of protocol conformances from superclasses.
Extend @objc inference for witnesses to also consider optional
protocols whose conformances come from superclasses. Because we don't
do real binding of witnesses for inherited conformances, this is a bit
of an heuristic, looking at whether the witness is a potential match
(vs. the known exact match), so it can infer @objc somewhat more
liberally than a complete solution.

Fixes rdar://problem/27348369.
2016-09-06 15:31:57 -07:00
Slava Pestov
1487d590a9 Merge pull request #4617 from slavapestov/kill-canonical-mangling-signature
Kill canonical mangling signature
2016-09-06 13:44:25 -07:00
Doug Gregor
9948a359e5 Merge pull request #4640 from DougGregor/infer-objc-extensions
[Type checker] Infer @objc for protocol conformances in other extensions
2016-09-06 13:05:06 -07:00
Doug Gregor
7e2efe5591 [Type checker] Infer @objc for protocol conformances in other extensions.
Expand the scope of @objc inference for witnesses to encompass
witnesses that are in a different extension from that of the
conformance, including cases where one or the other is in the nominal
type declaration itself.

Fixes rdar://problem/26892526.
2016-09-06 13:04:00 -07:00
Rintaro Ishizaki
a7fef2299f Merge pull request #4627 from rintaro/nowitness-stub
[Sema] Improve fix-it for missing initializer requirement
2016-09-07 04:10:19 +09:00
Slava Pestov
af56a0108c Sema: Add a couple of comments 2016-09-06 11:52:25 -07:00
Slava Pestov
2149061df1 Sema: Clean up hack forcing use of NSError-related conformances 2016-09-06 11:52:24 -07:00
Slava Pestov
db4464bf39 Sema: Remove unused parameter from ConformanceChecker::recordTypeWitness() 2016-09-06 11:52:24 -07:00
Slava Pestov
dc49f82c2a Sema: Eagerly mark associated type conformances as used
This might look like a regression in lazyness at first sight,
however this was previously being done implicitly by checking
the 'Self := Adoptee' substitution against the protocol's
generic signature, back when generic signatures had expanded
requirements for protocol associated types.

When generic signature minimization was switched on, this was
no longer being done, as a result it was possible to construct
code that would fail in the specializer with a missing
conformance.
2016-09-06 11:52:24 -07:00
Slava Pestov
38e58b23aa AST: Fix regression with reference-dependencies-members test
When the call to checkGenericArguments() was removed from
ConformanceChecker::checkConformance(), we stopped recording
a dependency on the extended nominal type when checking an
extension that adds a protocol conformance to the type.

Fix this in a hacky way by recording an explicit dependency
in the same place where we used to call checkGenericArguments().

Surely this is not the best place for it though, so this
should be revisited since I'm pretty sure the old behavior
was an accident.
2016-09-06 11:51:15 -07:00
Slava Pestov
3b1721795f AST: Nuke GenericSignature::getCanonicalManglingSignature()
Now that the previous patches have shaken out implicit assumptions
about the order of generic requirements and substitutions, we can
make a more radical change, dropping redundant protocol requirements
when building the original generic signature.

This means that the canonical ordering and minimization that we
used to only perform when building the mangling signature is done
all of the time, and hence getCanonicalManglingSignature() can go
away.

Usages now either call getCanonicalSignature(), or operate on the
original signature directly.
2016-09-06 11:51:14 -07:00
Slava Pestov
9771ec84dd Sema: Improve checking of associated type superclass constraints
When checking a conformance of a concrete type to a protocol, we
effectively checked the associated types twice -- once when
deriving them, and another time at the end, where we performed
a substitution of the protocol 'Self' type to the concrete type.

The latter checked superclass constraints, while the former did not.

However, this trick no longer works with minimized generic
signatures, because <P : Self> no longer has redundant requirements
for the associated types of 'P'.

Instead, check superclass constraints at the same time as checking
conformances.
2016-09-06 11:51:14 -07:00