Commit Graph

7589 Commits

Author SHA1 Message Date
Slava Pestov
ae35e4e069 Sema: Diagnose @_versioned on protocol requirements
Protocol requirements do not have accessibility distinct from that
of the protocol itself, and this also applies to @_versioned.
2017-01-20 01:22:50 -08:00
Slava Pestov
d6c857259d Sema: Diagnose @_fixed_layout when applied to internal types
This attribute is only meaningful for versioned and public types;
private and internal types are always fixed-layout.
2017-01-20 01:22:50 -08:00
swift-ci
41539284eb Merge pull request #6924 from graydon/rdar-28815071-fixit-to-narrow-availability-check 2017-01-20 01:22:28 -08:00
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -08:00
Slava Pestov
8de0ca54e5 Sema: Merge the two implementations of simplifyType()
ConstraintSystem::simplifyType() replaced types with their fixed types
from the global map.

Solution::simplifyType() replaced types with their fixed types from the
current bindings.

There were some minor differences between the two, and some dead code.
2017-01-19 20:07:06 -08:00
Slava Pestov
10e292bfdf Sema: Make it explicit that the 'tuple splat' diagnostic is only for Swift 3 compatibility mode 2017-01-19 20:07:06 -08:00
Slava Pestov
599021bf7b Sema: Simplify interface of Solution::computeSubstitutions()
Instead of passing the original type and DeclContext, we just
need a GenericSignature.
2017-01-19 20:07:05 -08:00
Slava Pestov
a22b46244c Sema: Don't canonicalize base type in member lookup
We would lose ParenType sugar in function types as a result.

Fixes part of <rdar://problem/29739905>.
2017-01-19 20:07:05 -08:00
Jordan Rose
d79fc62394 Don't try to infer @objc for non-getter/setter accessors (#6926)
These are never part of an @objc protocol, so we shouldn't bother
looking for them and certainly shouldn't expect them to be there.
Fixes a crash introduced in 1f2121377.

rdar://problem/30101703
2017-01-19 19:28:04 -08:00
Slava Pestov
cf5a88aa49 Merge pull request #6923 from slavapestov/fix-assoc-type-inference-regression
Sema: Teach getReferencedAssociatedTypes() to look through typealiases
2017-01-19 17:21:53 -08:00
Graydon Hoare
d94b76f396 Suggest narrowing an exising availability context, when feasible. 2017-01-19 16:29:16 -08:00
Slava Pestov
7370523386 Merge pull request #6910 from xedin/crasher-28636
[Diagnostics] Don't attempt member lookup if base type has unresolved type parameters
2017-01-19 15:55:09 -08:00
Slava Pestov
0926773c69 Sema: Teach getReferencedAssociatedTypes() to look through typealiases
Now that NameAliasTypes desugar to interface types, it is possible
to have a protocol requirement type contain a NameAliasType which
contains an associated type:

protocol P {
  associatedtype Element
  typealias Elements = [Element]

  func process(elements: Elements)
}

In Swift 3, the typealias would be desugared at name lookup time
in this case, but this is no longer the case, as a result associated
type inference stopped working in this example.

Fixes <https://bugs.swift.org/browse/SR-3641>.
2017-01-19 14:39:03 -08:00
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