Commit Graph

9116 Commits

Author SHA1 Message Date
Jordan Rose
ca1979c920 Improve diagnostics for setting a 'let' property in a delegating init 2017-11-09 18:08:01 -08:00
Jordan Rose
9888697544 Correctly check access control for a class's generic superclass (#12629)
The previous code was too clever in trying to avoid work and missed
the fact that ClassDecl::getSuperclass produces an interface type but
the types in the inheritance clause are contextual types.

This actually successfully built:

- in non-WMO builds with a public subclass and an internal base class,
  because the internal class symbol wouldn't get stripped out.

- in WMO builds with an internal subclass and a private base class,
  because 'private' has no distinction at the linkage level for a WMO
  build.

However, it's highly likely that trying to import a library containing
such types would result in instability (read: compiler and debugger
crashes), and it's clearly a mistake to allow this. (If you can't show
your superclass to a user in a library's generated interface,
something's definitely gone wrong.)

https://bugs.swift.org/browse/SR-6206
2017-11-09 13:29:24 -08:00
Joe Groff
73d2e9a47f Sema: Fixes for KeyPath type checking.
When testing KeyPathApplication constraints, we would keep going after rejecting a concrete KeyPath application by trying PartialKeyPath and AnyKeyPath, even though that's not what we want, since any key path application expression can type check with an AnyKeyPath. We would then miscompile by building the AST such that we applied the mismatched key path expression directly to the base. We also didn't handle expressions where the base was a subtype of the key path's base type correctly—the conversion means the base can't be written through in this situation, and we hardcoded the concrete-to-existential case instead of handling general conversions. Fix these problems, and add an AST verifier for KeyPathApplicationExprs to help catch problems in the future. Fixes SR-6300 | rdar://problem/35368903.
2017-11-09 11:57:23 -08:00
Doug Gregor
a49455e3b2 [Clang importer] Move the "all properties" lists into the name importer.
Swift's ASTContext contained all of the logic to find the complete list
of properties for an Objective-C class, which is used by the Clang importer
to influence the mapping of Objective-C names into Swift. Swift's
ASTContext also included a *cache* for this information, indexed by
the Clang `ObjCInterfaceDecl *`. However, this cache was getting
populated/queried from the Clang importer's name importer, such that
the keys would be Clang declarations used to build modules and then
deallocated. If that memory eventually gets reused for a different
`ObjCInterfaceDecl *`, we would get incorrect/stale all-properties
information.

Almost Surely fixes rdar://problem/35347167, which is a
nondeterministic failure where UIView's `addGestureRecognizer(_:)` gets
occasionally imported as `add(_:)`.
2017-11-08 15:25:15 -08:00
Doug Gregor
318a455314 [Type checker] Suppress near-miss warnings for unlabeled inits and subscripts.
Suggested by @brentdax, thanks!
2017-11-07 17:02:36 -08:00
Greg Titus
20a488225a Merge pull request #12642 from gregomni/6204
[Sema] Don't suggest adding 'as' in a pattern matching context where it will do no good.
2017-11-07 10:02:58 -08:00
Jordan Rose
674e687ebe Merge pull request #12410 from tjw/SR-1226
Fix transitive unavailability check
2017-11-07 09:39:52 -08:00
swift-ci
69a6e5e260 Merge pull request #12789 from rjmccall/sil-coroutines 2017-11-07 03:22:22 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
swift-ci
b0ef4b53e9 Merge pull request #12774 from DougGregor/gsb-validate-canonicalization 2017-11-06 22:18:32 -08:00
Doug Gregor
42868b3bd6 [Type checker] Replace a transformRec() with a subst().
We’re substituting in the conformance type for Self, nothing more.
2017-11-06 21:22:35 -08:00
Mark Lacey
401d046581 More SE-0054 fixes for Swift version 5.
Fix a couple more places where we should not allow IUOs and add
additional tests for these as well as parallel tests for the long
spelling ImplicitlyUnwrappedOptional.
2017-11-06 20:02:57 -08:00
Graydon Hoare
207a94ddd6 [Sema] Remove TypeChecker::addImplicitDestructor entirely. 2017-11-06 14:43:34 -08:00
Graydon Hoare
6d46fb144f [AST] Move copyFormalAccess to ValueDecl. 2017-11-06 14:31:21 -08:00
Slava Pestov
e805100f96 Sema: Fix source compatibility break with default initialization of optional properties
In Swift 4, properties declared with a sugared Optional type,
like Int?, have a default value of nil. This can be observed
in two ways:

- Classes and structs get an implicit no-argument initializer
- Designated initializers don't have to initialize this property

Note that this did not apply in general to properties where
the type was spelled explicitly as Optional<Int>, etc, mostly
because of implementation restrictions -- when we check if a
type has implicit initializers, we have not realized types for
all stored property members yet, and doing so is not really
possible without the iterative decl checker.

However, in some cases, we *did* perform default initialization
for Optional<Int>, because of some code duplication and
divergent code paths.

A recent refactoring cleaned up some of the mess in this area,
but accidentally broke source compatibility with code that
relied on the broken Optional<Int> case.

Fix this by simulating the old behavior in -swift-version 4,
and preserving the more correct behavior in -swift-version 5.

Fixes <rdar://problem/35319847>.
2017-11-04 23:40:24 -07:00
Slava Pestov
d8c5e798d5 Sema: Fix incorrect usage of NormalProtocolConformance in Codable synthesis
Noticed by inspection. It looks like there are no tests for generic
Codable types. I'm just adding one to cover the changed code path.
2017-11-04 23:40:24 -07:00
Slava Pestov
59f1133587 Sema: Do less work for structs in addImplicitConstructors() 2017-11-04 23:40:23 -07:00
Slava Pestov
4e8bdcd716 Sema: Type aliases with an unbound generic type cannot witness associated type requirements
We allow definitions like this:

struct G<T> {}
typealias A = G

As a shorthand for

typealias A<T> = G<T>

A typealias like this cannot satisfy an associated type requirement
for the same reason that a generic typealias cannot satisfy an
associated type requirement, which was already handled.

Previously this would crash in the type checker or in IRGen.

This fixes a weird regression in a fixed compiler crasher from the
next patch.
2017-11-04 23:40:23 -07:00
swift-ci
3e45eb75c9 Merge pull request #12763 from graydon/rdar-35198678-add-implicit-dtor-outside-typecheck 2017-11-04 05:00:19 -07:00
Graydon Hoare
7e363ff97a [AST] Add implicit dtors outside typechecking, rdar://35198678 2017-11-04 02:59:52 -07:00
Mark Lacey
6062204372 Merge pull request #12746 from rudkx/ban-iuo-in-tuple
Ban IUOs in more places.
2017-11-03 20:58:39 -07:00
Xi Ge
6af5d3c0bf libSyntax: rename KeepTokensInSourceFile to KeepSyntaxInfoInSourceFile. 2017-11-03 18:39:01 -07:00
Mark Lacey
b38d967784 Ban IUOs in more places.
We were allowing them in parens in some contexts, but shouldn't have.

Also added tests for function types and tuple return types to ensure
we're not allowing them in these places.
2017-11-03 18:35:01 -07:00
swift-ci
2e190d14eb Merge pull request #12756 from rudkx/allow-iuo-in-typeloc-parsing 2017-11-03 17:27:10 -07:00
Mark Lacey
9793e8ff17 Allow IUOs in SIL TypeLoc parsing. 2017-11-03 16:08:38 -07:00
Slava Pestov
759a9eee48 Merge pull request #12671 from hamishknight/subscript-non-escaping-args
[Sema] Allow non-escaping functions to be passed as subscript arguments
2017-11-03 13:12:43 -07:00
Mark Lacey
d83374449b Add a declaration attribute for implicitly unwrapped optional.
Attach this attribute to VarDecls declared as IUO, and to function decls
that have a result type that is an IUO.

NFC at the moment. Eventually we'll use these to determine where to
implicitly unwrap optional values.
2017-11-02 22:44:37 -07:00
Hamish
d734631120 [Sema] Allow non-escaping functions to be passed as subscript arguments 2017-11-02 11:04:53 +00:00
Huon Wilson
0236db7be1 [SIL] Witness methods store the conformance from which they come. 2017-11-01 11:33:26 -07:00
Pavel Yaskevich
ebe3abaff1 Merge pull request #12593 from xedin/rdar-35142121
[ConstraintSolver] Avoid unnecessarily increasing score when matching function types
2017-11-01 00:47:37 -07:00
Pavel Yaskevich
66e13bcc85 [ConstraintSolver] Avoid unnecessarily increasing score when matching function types
Remove function-to-function type match score increase, which should only
happen contextually in presence of other restrictions, this used to fix
the case related to matching of arrays of functions with and w/e `throws`
as function parameters which used to be ambigious, and now handled by
collection-upcast conversion score.

Resolves: rdar://problem/35142121
2017-10-31 23:14:35 -07:00
Slava Pestov
ae5f93076e Merge pull request #12699 from slavapestov/coerce-to-rvalue-cleanup
Sema: coerceToRValue() never returns nullptr
2017-10-31 22:19:13 -07:00
Mark Lacey
39473e946a Merge pull request #12695 from rudkx/fix-illegal-iuo-errors
Fix more places where were allowing IUOs but shouldn't.
2017-10-31 20:24:47 -07:00
Slava Pestov
4eef3615ee Sema: coerceToRValue() never returns nullptr 2017-10-31 20:22:41 -07:00
Slava Pestov
398f76d12b Sema: Check AnyObject constraint on associated type witnesses
Fixes <https://bugs.swift.org/browse/SR-6109>, <rdar://problem/34911213>.
2017-10-31 19:35:31 -07:00
Slava Pestov
bcb874b446 Sema: Refactor type witness checking a bit 2017-10-31 19:35:31 -07:00
Mark Lacey
cef6c9463c Fix more places where were allowing IUOs but shouldn't.
My previous commit, f9b82bccb7, failed to
ensure that IUOs could not be nested inside of other types in all
positions.
2017-10-31 18:58:55 -07:00
Slava Pestov
82999d8177 Sema: Don't allow @_inlinable or @_versioned to be applied to dynamic declarations 2017-10-31 13:37:20 -07:00
Davide Italiano
330fb1ce2f [gardening] Remove some unused variables. NFCI. 2017-10-30 15:19:55 -07:00
Doug Gregor
439bb8cc2b Make sure that TypeChecker::validateExtension() wires up generic environment.
Fixes a crasher.
2017-10-27 23:41:08 -07:00
Doug Gregor
5947ae9c00 Merge pull request #12645 from DougGregor/conformance-near-miss
Warn on “near-misses” when defaults are used for protocol witnesses.
2017-10-27 23:01:59 -07:00
Mark Lacey
93d827f276 Merge pull request #12653 from rudkx/repay-iou-for-iuo
Ban IUOs in illegal positions harder under Swift 5 and later.
2017-10-27 00:43:33 -07:00
Slava Pestov
5c45f8546f Merge pull request #12614 from slavapestov/imported-materialize-for-set-override-bugs
Sema: Fix some issues with overrides of materializeForSet
2017-10-26 22:49:08 -07:00
Mark Lacey
f9b82bccb7 Ban IUOs in illegal positions harder under Swift 5 and later.
SE-0054 specified that the use of implicitly unwrapped optionals was
limited to just a few places, but the implementation at the time did not
completely ban the other uses. This is another attempt to do so, but
it's only on for compilations in Swift 5 mode and later.

For earlier versions, we fall back on the existing implementation.

Fixes: rdar://problem/27707015
2017-10-26 22:21:36 -07:00
Mark Lacey
f53826afd9 Merge pull request #12631 from rudkx/warn-on-iuo-spelling
Add a warning that ImplicitlyUnwrappedOptional is deprecated
2017-10-26 20:45:38 -07:00
Mark Lacey
e07a7362cf Add a warning that ImplicitlyUnwrappedOptional is deprecated in 4+.
Per SE-0054, implicitly unwrapped optional is not a distinct type in the
type system, but rather just the notion that certain Optionals (denoted
by the sigil "!" rather than "?") can be implicitly unwrapped.

This is a first step in the direction of implementing this notion by
emitting a warning if the type is spelled out.
2017-10-26 18:09:26 -07:00
Slava Pestov
0f2da217a4 Sema: Fix some issues with overrides of materializeForSet
When overriding storage with a forced static dispatch materializeForSet,
the override's materializeForSet should not override the base
materializeForSet.

This is the case where a dynamic property witnesses a protocol
requirement, and Sema synthesizes a materializeForSet for it.

In this case, the synthesized materializeForSet dynamically dispatches
to the dynamic property's getter and setter, and the protocol witness
thunk directly calls the synthesized materializeForSet.

The subclass only needs to override the getter and setter in this case,
since the base class's materializeForSet will already do the right
thing.

In fact, marking it as an override exposes a problem where we cannot
serialize an xref to an imported property's materializeForSet, since
it was not created by the importer.
2017-10-26 17:11:09 -07:00
Doug Gregor
493d4da667 Warn on “near-misses” when defaults are used for protocol witnesses.
When a particular nominal type or extension thereof declares conformance
to a protocol, check whether that type or extension contains any members
that *nearly* match a defaulted requirement (i.e., a requirement that 
is satisfied by something in a protocol extension), but didn’t match
for some reason and weren’t used to satisfy any other requirement of
that protocol. It’s intended to catch subtle mistakes where a default
gets picked instead of the intended member.

This is a generalization of the code we’ve had for @objc optional
requirements for a long time.

Fixes rdar://problem/24714887.
2017-10-26 17:04:46 -07:00
gregomni
55edab880f Don't suggest adding 'as' in a pattern matching context where it will do no good. 2017-10-26 15:51:59 -07:00
Doug Gregor
e1e0deca33 Reject unbound generic types in case patterns.
Fixes SR-6100 / rdar://problem/34898452.
2017-10-25 23:19:28 -07:00