Commit Graph

7976 Commits

Author SHA1 Message Date
Pavel Yaskevich
671d470322 [Diagnostics] Don't attempt member lookup if base type has unresolved type parameters
If there are unresolved generic parameters present and we are trying
to diagnose problems related to initializer call, it makes sense to
check argument expression first, which might be erroneous and then move
on to the ambiguity checking instead of trying to lookup possible
constructors directly.
2017-01-19 14:01:57 -08:00
swift-ci
111b2361f1 Merge pull request #6917 from DougGregor/compare-dependent-types 2017-01-19 12:28:39 -08:00
Doug Gregor
d947ed33c0 [Archetype builder] Stub out getNestedType() for associated types. NFC
Start using this entrypoint when we have a specific associated
type. The eventual goal here is to create the invariant

  resolveArchetype(t)->getDependentType()->isEqual(t)

when t has fully-resolved DependentMemberTypes.
2017-01-19 10:40:08 -08:00
Roman Levenstein
085e7bcf3e Type checking for the @_specialize attribute. 2017-01-18 16:43:42 -08:00
Slava Pestov
24b2531e5f AST: Have SubstitutionMaps manage the memory for the conformance array 2017-01-18 00:15:59 -08:00
Slava Pestov
81d46a3084 Sema: Follow-on fix for <https://github.com/apple/swift/pull/6267>
Fixes <https://bugs.swift.org/browse/SR-3656>.
2017-01-17 23:06:16 -08:00
Joe Groff
0ab904c4e5 Merge pull request #6865 from jckarter/warn-on-plus-initialize-method
Sema: Warn when Swift classes attempt to implement ObjC +initialize.
2017-01-17 16:03:31 -08:00
swift-ci
36ab93a95d Merge pull request #6860 from DougGregor/optional-conversions 2017-01-17 15:11:12 -08:00
Joe Groff
fb4a769f05 Sema: Warn when Swift classes attempt to implement ObjC +initialize.
Swift's language model doesn't guarantee that type metadata will ever really be used, which makes overriding initialize() error-prone and not really any better than manually invoking an initialization function. Warn about this for Swift 3 compatibility and reject attempts to override +initialize in Swift 4.
2017-01-17 15:06:44 -08:00
Doug Gregor
0d4f053561 [Type checker] Fix optional-to-optional expression AST creation.
Constraint application had a "peephole" to try to generate a series of
optional-injection expressions when performing an optional-to-optional
coercion such as "Int??!" to "Int?????!". However, the computation
incorrectly selecting between implicitly-unwrapped optional and
optional types for intermediate steps, leading to an AST verification
failure. Clean up the implementation to use
TypeBase::lookThroughAllAnyOptionalTypes() rather than hand-rolled,
more-lossy versions and use the actual optional types in the "to" type
along each step, which has the side effect of maintaining type sugar.
2017-01-17 14:46:18 -08:00
Jordan Rose
29b59342f8 Merge pull request #6346 from KingOfBrian/bugfix/SR-584
Warn if a non dynamic class declaration is overridden in an extension
2017-01-17 13:47:42 -08:00
Doug Gregor
ecfea608db [Type checker] Classify the various optional conversion kinds.
1efafbcd9b restricted our classification
of various optional-related conversions (implicit forcing of IUOs,
optional-to-optional conversions, value-to-optional conversions) to
produce a single potential classification. However, in the presence of
type variables, we cannot always determine which particular conversion
restriction might apply. Prior to 1efafb, we produced too many
options; after 1efafb, we produced too few. Here, enumerate a more
bounded (but complete) set of potential conversions, taking into
account embedded type variables.

This is a better fix for rdar://problem/29977523 than simply reverting
1efafb, because it bounds the set of optional conversions we attempt.
2017-01-17 13:10:26 -08:00
Pavel Yaskevich
35b0ffeff8 [Diagnostics] Fix diagnoseImplicitSelfErrors to accept only valid argument types.
Add additional checks before trying to re-check argument expression in
`FailureDiagnosis::diagnoseImplicitSelfErrors` and before trying to use
its resulting type, which can only be either tuple or paren type.
2017-01-17 01:49:09 -08:00
Slava Pestov
b8bfd8007e Merge pull request #6806 from xedin/SR-3525
[Diagnostics] Nullify contextual type if it's generic with type variables
2017-01-16 18:48:23 -08:00
Slava Pestov
c49be072d1 Merge pull request #6826 from xedin/implicit-cleanup
[QoI] Move from RAII to direct sub-expression cleanup. NFC
2017-01-16 15:47:42 -08:00
Slava Pestov
c0b79621f8 Merge pull request #6837 from hughbe/delet-this
Introduce and use SWIFT_DELETE_OPERATOR_DELETED
2017-01-16 15:46:03 -08:00
Hugh Bellamy
201ad5d594 Prefix COMPILER_IS_MSVC with SWIFT_ 2017-01-16 22:09:53 +00:00
Rintaro Ishizaki
3952e0043c [Diag] Don't attempt 'fixOverrideDeclarationTypes' when indices count doesn't match for subscript
Fixes a crasher
2017-01-16 22:51:35 +09:00
Pavel Yaskevich
24e8cdfdc1 [Diagnostics] Nullify contextual type if it's generic with type variables
It's undesirable to have generic type which contains type variables
as contextual conversion type while diagnosing sub-expressions, it's
going to result in attempt to convert generic arguments to unresolved
type which produces worse diagnostics than no contextual type at all.

Resolves: SR-3525.
2017-01-16 00:33:45 -08:00
Mark Lacey
c301833e15 Reapply: Collapse the three optional-to-optional restriction kinds.
This reapply's Doug's change d79ba781c6,
which had previously been applied on top of
1efafbcd9b, the latter of which resulted
in a source compatibility break.
2017-01-15 22:34:40 -07:00
Mark Lacey
fc73e79b74 Revert "Fix one source of exponential behavior in the type checker."
This reverts commit 1efafbcd9b because
results in a regression in source compatibility with Swift 3.

It also adds a test demonstrating what was broken by the change.

I will take another look at fixing the exponential behavior that this
was attempting to fix.

Fixes rdar://problem/29977523.
2017-01-15 22:33:57 -07:00
Mark Lacey
7dd2489151 Revert "[Constraint solver] Collapse the three optional-to-optional restriction kinds."
This reverts commit d79ba781c6 so that I
can revert 1efafbcd9b, which caused a
source compatibility regression.
2017-01-15 22:01:45 -07:00
Slava Pestov
4e14823045 Merge pull request #6811 from hughbe/constraint-warnings
Fix signed warnings compiling lib/Sema/ConstraintSystem.h
2017-01-15 17:31:21 -08:00
Slava Pestov
48da014393 Merge pull request #6828 from hughbe/compiler-is-msvc
Introduce and use COMPILER_IS_MSVC
2017-01-15 17:29:40 -08:00
Pavel Yaskevich
6f217dbe2a [ConstraintSystem] Don't attempt to solve candidates which have closures.
While shrinking constraint system, avoid candidates which contain
closures inside, because closure expressions require special handling
and allow no rollback.
2017-01-15 14:15:04 -08:00
Brian King
7d8d275722 Only generate a warning in swift 3 2017-01-15 17:05:01 -05:00
Brian King
7dcab1255d Update PR comments 2017-01-15 17:05:01 -05:00
Brian King
f7a7ee941a Warn if a non dynamic class declaration is overridden in an extension 2017-01-15 17:05:01 -05:00
Jordan Rose
8d164c5370 Merge pull request #6795 from jrose-apple/access-reluctantly-granted
Use Swift-3-style access checking to downgrade errors to warnings

Part of rdar://problem/29855782.
2017-01-15 11:30:39 -08:00
Hugh Bellamy
cf777d04f5 Introduce and use COMPILER_IS_MSVC 2017-01-15 15:17:18 +00:00
Pavel Yaskevich
6f74251803 [QoI] Move from RAII to direct sub-expression cleanup. NFC 2017-01-15 04:36:10 -08:00
Hugh Bellamy
b3ade87eee Fix signed warnings compiling lib/Sema/ConstraintSystem.h 2017-01-15 10:36:11 +00:00
Hugh Bellamy
2445862e1b FIx recently introduced MSVC control path warnings 2017-01-14 12:40:41 +00:00
Pavel Yaskevich
488fc0fad5 [QoI] Cleanup AST after trying to shrink constraint system of invalid expression
Since `ConstraintSystem::shrink` is going to attempt to type-check
sub-expressions separately it's essential to clean-up AST if constraint
generation or solving of the such expressions fails, otherwise if
such solving resulted in creation of implicit expression type variables
might leak to the outside.
2017-01-13 17:20:56 -08:00
swift-ci
a716d403d6 Merge pull request #6774 from jckarter/nsnumber-conditional-casting 2017-01-13 15:20:12 -08:00
Jordan Rose
9489f10ce1 Use Swift-3-style access checking to downgrade errors to warnings.
...instead of just ignoring the errors in certain cases, in service of
source compatibility.

Swift 3.0 wasn't nearly as strict as checking access control for types
because it didn't look at the TypeRepr at all (except to highlight a
particular part of the type in diagnostics). It also looked through
typealiases in certain cases. Approximate this behavior by running the
access checking logic for Types (rather than TypeReprs), and downgrade
access violation errors to warnings when the checks disagree.

Part of rdar://problem/29855782.
2017-01-13 14:34:50 -08:00
Jordan Rose
9c0f690c20 Thread an extra DowngradeToWarning parameter through access checking.
No functionality change; the value at the place where the callback is
invoked is always DowngradeToWarning::No. This will be exercised by
the next commit.
2017-01-13 14:34:50 -08:00
swift-ci
116b2397a8 Merge pull request #6794 from apple/revert-6780-keypath-crashers 2017-01-13 14:13:38 -08:00
Erik Verbruggen
c5018122ad An unused @ discardableResult should not throw an error (#6785)
A function marked with @discardableResult should not throw an error if
its returning closure is unused.

Fixes SR-2948.
2017-01-13 14:03:17 -08:00
Joe Groff
c03371afc1 Sema: NSValue-to-value-type casts are failable and should be checked.
In Swift 4 mode, no longer consider e.g. 'nsNumber as Int' or 'nsValue as NSRange' to be valid coercions. This would break compatibility with Swift 3, so in Swift 3 mode, accept the coercion, but *also* accept a checked cast without a warning, and raise a migration warning about the unchecked coercion.
2017-01-13 13:51:27 -08:00
Arnold Schwaighofer
e46e63ebc6 Revert "[QoI] Cleanup AST after trying to shrink constraint system of invalid expression" 2017-01-13 13:35:19 -08:00
Mark Lacey
a94b2dd7b5 Merge pull request #6780 from xedin/keypath-crashers
[QoI] Cleanup AST after trying to shrink constraint system of invalid expression
2017-01-13 11:43:26 -08:00
Pavel Yaskevich
9b7d632160 [QoI] Cleanup AST after trying to shrink constraint system of invalid expression
Since `ConstraintSystem::shrink` is going to attempt to type-check
sub-expressions separately it's essential to clean-up AST if constraint
generation or solving of the such expressions fails, otherwise if
such solving resulted in creation of implicit expression type variables
might leak to the outside.
2017-01-13 00:39:37 -08:00
swift-ci
c7f7706658 Merge pull request #6773 from DougGregor/simplify-iuo-kinds 2017-01-12 21:01:52 -08:00
Slava Pestov
8fff45d932 Merge pull request #6770 from xedin/cgr-refactor
[QoI] Refactor TypeChecker::checkGenericArguments. NFC
2017-01-12 19:23:49 -08:00
Doug Gregor
2fab44ab5a Merge pull request #6767 from rudkx/fix-rdar29907555
Disallow conversions from IUOs to extistentials.
2017-01-12 18:58:20 -08:00
Pavel Yaskevich
599be90009 [QoI] Refactor TypeChecker::checkGenericArguments. NFC
Refactor TypeChecker::checkGenericArguments to enable it
to be used by FailureDiagnosis::diagnoseArgumentGenericRequirements,
which consolidates requirement checking in one place.
2017-01-12 18:41:18 -08:00
Doug Gregor
d79ba781c6 [Constraint solver] Collapse the three optional-to-optional restriction kinds.
All three of these conversion restriction kinds were handled in
exactly the same way, so just treat them as one.
2017-01-12 17:11:13 -08:00
Mark Lacey
5c6c7ff651 Disallow conversions from IUOs to extistentials.
Commit 170dc8acd7 removed a penalty that
we used to have for conversions to Any. In some unusual circumstances
not having that penalty can result in new amiguities where we should
have nothing ambiguous about an expression according to our type rules.

This change attempts to ensure that we make that less likely or
impossible by not allowing direct conversions from IUOs to Any (instead
forcing these to first be force-unchecked, leading to more expensive
solutions). We never should have allowed these conversions anyway,
independent of removing the penalty for conversions to Any.

This change is intentionally very narrow to avoid further potential
source breakage.

Fixes rdar://problem/29907555.
2017-01-12 16:45:53 -08:00
Doug Gregor
14913d3b04 [Type checker] Stop using PotentialArchetype::getRepresentative().
The representative of a potential archetype is an internal
data-structure issue that shouldn't be used outside of the archetype
builder itself.
2017-01-12 16:10:34 -08:00