Commit Graph

757 Commits

Author SHA1 Message Date
Slava Pestov
18082b1b3f Sema: Don't set "validation started" bit on typealiases in the ITC
This appears to do nothing except cause a crash.
2017-06-06 23:56:33 -07:00
Slava Pestov
c49a1d77d2 AST: Stricter DeclContext::getParentForLookup() 2017-06-06 23:56:32 -07:00
Slava Pestov
9e1f60d751 Sema: Skip an invalid kind of nested type in name lookup 2017-06-06 23:56:31 -07:00
Slava Pestov
55ffbe8cce AST: Fix Type::transform() for protocol compositions
There was undefined behavior here; we were calling
members.append(members.begin(), members.begin() + index),
which is invalid because 'members' is the new array of
members being built, which is empty at this point!
2017-06-06 23:27:54 -07:00
Slava Pestov
1bd91dee5c Sema: Fix crash with unbound generic types in patterns 2017-06-06 00:35:02 -07:00
Slava Pestov
e5becab4ac Sema: Fix crashes when applying solution with error types or unresolved types 2017-06-05 23:50:30 -07:00
Slava Pestov
433b7f276e Sema: Fix bug with name lookup from initializers 2017-06-05 23:11:53 -07:00
Robert Widmann
25901cc467 Merge pull request #10065 from CodaFi/shame-on-you-shame-on-your-cow
Change an assertion to an ad-hoc circularity check
2017-06-02 11:40:06 -07:00
Robert Widmann
12f81163b1 Change an assertion to an ad-hoc circularity check 2017-06-02 10:23:02 -07:00
swift-ci
032c18c426 Merge pull request #10064 from CodaFi/thats-not-my-name 2017-06-02 00:37:12 -07:00
Robert Widmann
72ee26a52f Resolve a crasher 2017-06-01 23:58:14 -07:00
Jordan Rose
63bc717963 Error when one associated type is constrained to another. (#10053)
(...is constrained to be a subtype of another)

Previously the compiler would just mark the entry in the inheritance
clause invalid and move on without emitting any errors; in certain
circumstances in no-asserts builds this could actually lead to
everything working "correctly" if all conforming types happened to
pick the same concrete type for both associated types. In Swift 4 this
can actually be enforced with a same-type requirement, which will
guarantee that the two associated types are the same even in generic
contexts.

This fix avoids assertions and crashes, but the diagnostic is still
incorrect, and in the simple case of the inheritance clause it's
redundant. Doing something better and possibly even downgrading it to
a warning in Swift 3 mode is tracked by rdar://problem/32409449.

Initial patch by Slava, fixed up by me.
2017-06-01 19:45:34 -07:00
Doug Gregor
a9733cb8db [GSB] Resolve dependent member types in same-type and superclass constraints.
Once we're finalizing same-type-to-concrete and superclass
constraints, replace any unresolved DependentMemberTypes with their
resolved counterpairs. This allows us to simplify
DependentGenericTypeResolver, which only builds unresolved
DependentMemberTypes now, and eliminates the penultimate use of
ArchetypeResolutionKind::AlwaysPartial.
2017-05-30 11:43:53 -07:00
Pavel Yaskevich
da4232e546 [Diagnostics] Fix checking for presence of type variables in closure return expression
Instead of validating sub-expressions included in the closure's result
`diagnoseAmbiguousMultiStatementClosure` was only checking parent expression
by mistake.
2017-05-30 02:42:56 -07:00
Jacob Bandes-Storch
b7fe4e2355 [Parse] Fix InFlightDiagnostic lifetime (#9961)
Fixes @practicalswift's crasher 28759 (#9907), which seems to have been introduced in #9294.
2017-05-27 13:38:05 -07:00
Jacob Bandes-Storch
035179331b [CSDiag] Fix crasher in KeyPathExpr diagnosis (#9962)
New KeyPathExpr diagnosis recently added in #9845 did not work for Obj-C key paths.
2017-05-27 13:36:56 -07:00
Slava Pestov
39d0385e10 Sema: Fix a crasher by removing TVO_CanBindToInOut in a couple of spots 2017-05-26 23:47:10 -07:00
Slava Pestov
fc21ecce68 AST: Don't return hasTypeParameter() for DependentMemberTypes with an ErrorType base
Instead, introduce a new hasDependentMember() recursive property.

The only place that cares about this is associated type inference,
where I changed all existing hasTypeParameter() checks to instead
check (hasTypeParameter() || hasDependentMember()). We could
probably refine this over time and remove some of the
hasTypeParameter() checks, but I'm being conservative for now.

Fixes <https://bugs.swift.org/browse/SR-4575> and
<rdar://problem/31603113>.
2017-05-26 18:10:13 -07:00
Slava Pestov
1c7428666a Sema: Update isExtensionApplied() for primitive AnyObject 2017-05-24 22:09:23 -07:00
Slava Pestov
d8234bace6 Sema: Fix double type checking of lazy initializer expressions
If a lazy var has no declared type, we have to type check the
initializer to get a type before we can build the getter.

Then, the initializer is type checked as part of the getter
again.

Use the new SkipApplyingSolution flag when type checking for
the first time. We still end up doing redundant work, but by
not applying the solution we avoid feeding invalid AST nodes
back into the constraint solver.

This fixes some bad diagnostics and crashes.

Fixes <https://bugs.swift.org/browse/SR-2616> and
<rdar://problem/28313602>.
2017-05-24 17:21:28 -07:00
Slava Pestov
fa155bf1d1 Sema: Rework typeCheckBinding() to use the new foundSolution() callback
Record the initializer type as soon as we have a solution, before
it is applied, and get the type from the constriant system instead
of from the final type checked expression.

Note that the coerceToMaterializable() was unnecessary, since we
always coerce the value to an rvalue type with coerceToType().

Eventually coerceToMaterializable() should go away.

This is mostly NFC, except using the result of simplifyType() rather
than the type of the final expression changes some diagnostics where it
appears we were previously losing sugar.

Also this accidentally fixes a crasher. Unfortunately the underlying
issue is still there (applying a solution has bugs with opened
existentials "leaking" out) -- this merely masks the problem by
getting the initializer type directly from the constriant system.
2017-05-24 17:21:28 -07:00
Joe Groff
2e04e24ad8 Merge pull request #9760 from jckarter/sibling-nested-generic-call
Sema: Bind context generic params using the current ConstraintSystem's generic environment instead of the decl's DC.
2017-05-19 13:14:26 -07:00
Joe Groff
d16eb33477 Sema: Bind context generic params using the current ConstraintSystem's generic environment instead of the decl's DC.
Fixes SR-4833.
2017-05-19 10:47:57 -07:00
Dave Abrahams
4660a77816 Patch up tests per https://github.com/apple/swift/pull/9689 2017-05-17 17:17:49 -07:00
Dave Abrahams
9f37da8bb6 Merge branch 'master' into string-init-from-character-speedup 2017-05-17 12:23:56 -07:00
Dave Abrahams
4db3509ad6 [stdlib] A Character's buffer should only contain 1 grapheme
This speeds up construction of a String from large Character representations,
and various other operations that would otherwise require additional grapheme
breaking just to interpret the Character.
2017-05-17 10:06:35 -07:00
Slava Pestov
e58ae766a3 Fix and un-XFAIL regressed crashers from recent stdlib change 2017-05-17 05:51:51 -07:00
Doug Gregor
cf5424b617 [GSB] Move the Recursive(Concrete|Superclass)Type bits into EquivalenceClass.
Recursive concrete and superclass constraints are detected
per-equivalence-class; record them that way.

Use that information to drop recursive concrete and superclass
constraints from the resulting signature, which frees the canonical
generic signature builder from having to worry about such recursive
constraints. This eliminates the invalid-code crashes introduced in
the prior commit that disabled finalization for the canonical GSBs, as
well as fixing one other random crash-on-invalid.
2017-05-15 22:05:07 -07:00
practicalswift
6fc2efbe49 Merge pull request #9572 from practicalswift/gardening-20170513
[gardening] Remove assert requirement from fixed crashers. Fix spacing. Remove unused variables.
2017-05-15 14:00:21 +02:00
Ben Cohen
ea2f64cad2 [stdlib] Add Sequence.Element, change ExpressibleByArrayLiteral.Element to ArrayLiteralElement (#8990)
* Give Sequence a top-level Element, constrain Iterator to match

* Remove many instances of Iterator.

* Fixed various hard-coded tests

* XFAIL a few tests that need further investigation

* Change assoc type for arrayLiteralConvertible

* Mop up remaining "better expressed as a where clause" warnings

* Fix UnicodeDecoders prototype test

* Fix UIntBuffer

* Fix hard-coded Element identifier in CSDiag

* Fix up more tests

* Account for flatMap changes
2017-05-14 06:33:25 -07:00
practicalswift
4f05554682 [gardening] Remove assert requirement from fixed crashers 2017-05-13 10:57:05 +02:00
swift-ci
cd61cf6d1b Merge pull request #9494 from DougGregor/common-return-type-cleanup 2017-05-11 09:46:49 -07:00
Doug Gregor
ecdc993881 [Type checker] Tolerate invalid expressions in the error-handling checker.
When errors occur in the processing of expressions, we can end up with
invalid ASTs where the application of an operator declared within a
type is missing its "self" argument. Tolerate such ASTs in the
error-handling checker.
2017-05-11 08:57:29 -07:00
Roman Levenstein
f860741b05 Update tests 2017-05-10 16:31:08 -07:00
swift-ci
6f0ddedfaf Merge pull request #9219 from xedin/closure-arg-diag 2017-05-08 23:58:36 -07:00
Pavel Yaskevich
ddaccf88bb [QoI] Properly diagnose closure parameter distructuring after SE-0110
Swift 3 supported limited argument destructuring when it comes to
declaring (trailing) closures. Such behavior has been changed by
SE-0110. This patch aims to provide better error message as well
as fix-it (if structure of the expected and actual arguments matches)
to make the migration easier and disambiguate some of the common
mistakes.

Resolves: SR-4738, SR-4745, rdar://problem/31892961.
2017-05-08 23:04:37 -07:00
practicalswift
59cf379b17 [gardening] Remove "REQUIRES: asserts" from fixed crashers 2017-05-08 21:51:50 +02:00
Slava Pestov
2fe863266c AST: Fix crashes when name lookup finds declarations outside of a protocol or extension that's nested in another type
When performing a name lookup from inside of a protocol
or extension, skip directly to the source file context
when we are done visiting the protocol or extension.

Otherwise, if we have invalid code where the protocol
or extension is nested inside another type, we might
find a member whose type contains generic parameters
of the outer type; these parameters will not resolve,
since we do not model protocols or extensions nested
inside generic contexts (yet?).

This supercedes an earlier workaround for a similar
issue; the new workaround fixes more crashes.

This is needed to avoid crasher regressions with an
upcoming patch.
2017-05-07 03:01:47 -07:00
Doug Gregor
3dbfa9789f [Associated type inference] Check solutions against full requirement signature
When we have a potential assignment of associated types to type
witnesses during associated type inference, check that set of type
witnesses against the requirements in the requirement signature, so
that we can reject any solutions that fail some of the protocol's
requirements.

This is most of rdar://problem/31830524 --- but gets thwarted by the
inability of associated type inference to work across multiple
protocols.
2017-05-04 00:21:52 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Slava Pestov
0d4a0b7dc1 AST: Update ProtocolDecl::requiresClass() for primitive AnyObject 2017-05-01 16:43:51 -07:00
Ben Cohen
deb8a8889a Delete old test that no longer makes sense (#9021) 2017-04-26 05:41:56 -07:00
Maxim Moiseev
1c1b2b966d [stdlib] String : RangeReplaceableCollection & BidirectionalCollection (#8921)
* [stdlib] String : RangeReplaceableCollection & BidirectionalCollection

* Add source compatibility hack for Swift.max

* Add source compatibility hack for Swift.min

* Remove redundant conformance in benchmarks

* Fix stupid typo I thought I'd already pushed

* XFAIL testing now-redundant conformance

* XFAIL an IDE test for now
2017-04-23 20:04:54 -07:00
Slava Pestov
aaca0badf9 Sema: Diagnose invalid references to type alias members of unbound generic types
Consider the following setup:

struct GenericStruct<T> {
  typealias Dependent = T
  typealias Concrete = Int
}

We have no way to model 'GenericStruct.Dependent' in the AST, so the
reference would crash. Instead, produce a diagnostic suggesting to
insert generic parameters, like 'GenericStruct<Int>.Dependent'.

The reference 'GenericStruct.Concrete' is fine though, and should
not crash; add a test that it works.

Fixes <https://bugs.swift.org/browse/SR-4390>, <rdar://problem/31480755>.
2017-04-23 00:02:30 -07:00
practicalswift
52fd78a5fc [gardening] Remove assert requirement for fixed crasher 2017-04-18 19:15:42 +02:00
Slava Pestov
9319a531f2 AST: Stricter contract for Type::subst()
Fix an odd corner case when UseErrorTypes was off; we would
return the empty type if dependent member type substitution
failed, but otherwise return the original type if it was a
generic type parameter or an archetype.

Now, if UseErrorTypes is off, return the empty type in both
cases, even if the original type is 'primary'.
2017-04-17 18:04:05 -07:00
practicalswift
288aff04e9 [gardening] Remove assert requirement for fixed crasher 2017-04-14 17:33:24 +02:00
Doug Gregor
0f0a5906d7 [GSB] Put conformance requirements on the proper potential archetype.
We were putting conformance requirements on the representative of the
equivalence class, rather than directly on the potential archetype on
which the conformance requirement was specified. This violates the
invariant used when forming protocol-requirement sources that we never
reseat a requirement onto the representative (which would
have become a problem when implementing recursive protocol
constreaints) as well as masking a GSB idempotency issue that comes
from same-type requirements where the right-hand side was not
guaranteed to refer to the archetype anchor *within* that subcomponent.
2017-04-11 14:15:46 -07:00
Slava Pestov
011fb8117a Sema: Fix a compiler crasher 2017-04-10 17:04:35 -07:00
Doug Gregor
5c89eb84f0 [AST] Drop substitutions from type witnesses.
Nobody is using the actual substitutions, but we sure did a lot of
work to cope with them.
2017-04-05 11:21:38 -07:00