Commit Graph

481 Commits

Author SHA1 Message Date
swift-ci
2195b73f07 Merge pull request #11772 from rudkx/test-for-rdar31529413 2017-09-05 14:04:22 -07:00
Mark Lacey
86e2bdab92 Add a test case for rdar://problem/31529413.
This crasher was fixed at some point but I don't know what change it
was.
2017-09-05 12:40:06 -07:00
Mark Lacey
f566d8d295 Switch test from 'not ...' to positive test with the correct verify check. 2017-09-05 12:38:17 -07:00
Max Moiseev
4c0368a02a [test] Cleaning up tests 2017-08-29 10:04:39 -07:00
Pavel Yaskevich
2d49d1202c [QoI] Fix crash while trying to compute default parameters
Arguments and parameters are not guaranteed to line-up perfectly,
because failure diagnostics sometimes has to match one argument
to different "candidate" parameters to see which one is closer,
so let's teach `computeDefaultMap` to respect that.

Resolves: rdar://problem/33433087.
2017-08-22 17:23:17 -07:00
Slava Pestov
bf8add0c01 Add regression test for rdar://33365139, which was fixed at some point 2017-08-14 00:31:57 -04:00
Doug Gregor
bebac49cee [GSB] Form minimal requirement sources by removing redundant subpaths.
When we detect that a requirement source is self-derived, identify the
redundant subpath and remove it to produce a new, smaller requirement
source that computes the same result. We were doing this form the
limited case where the redundant subpath ended at the end of the
requirement source; generalize that notion.

Fixes SR-5601.
2017-08-10 17:00:07 -07:00
Slava Pestov
1221bd8f60 Sema/AST: Fix a couple of protocol typealias validation order bugs
We break name lookup circularities by special-casing validation of
type aliases, resolving the underlying type of the type alias before
building the generic environment of the protocol that contains the
type alias.

However doing this gives the type alias an underlying type written
in terms of unresolved DependentMemberTypes which do not map to
associated types.

Attempting to substitute such a type fails.

We worked around this by re-validating type alias members of
protocols when we finally got around to building the protocol's
generic environment. Force this to happen earlier in
substMemberTypeWithBase(), because we need the fully resolved
underlying type in order to perform the substitution.

Also, fix TypeAliasDecl::setUnderlyingType() to only create a new
NameAliasType the first time it is called. In this special case
where it can be called twice with a resolved underlying type the
second time, we should not be creating a new NameAliasType.

There are better fixes possible here, requiring various levels
of refactoring. I'll investigate this soon, but for now this narrow
fix should address the problem with minimal risk.

Fixes <rdar://problem/33189068>.
2017-07-23 17:34:38 -07:00
Pavel Yaskevich
481401f6c3 [QoI] Don't try to lookup members on incorrect type during Objective-C KeyPath validation
While trying to validate Objective-C keypath components
don't assume that type of the component is always correct, check
before trying to see if it's bridged type or has members.

Resolves: rdar://problem/33044867
2017-07-12 14:04:10 -07:00
Mark Lacey
8d9f97cdc5 Fix another subtle SE-0110-related break.
The change to roll back a part of SE-0110 to allow multi-argument
functions to be passed in places where functions taking a tuple are
expected resulted in a regression in some cases where the fix would
strip off the last ParenType from single-argument functions.

Instead of stripping off parens from both function types we're trying to
match when they both have them, strip off none. This ensures that we
don't get summarily rejected in the nested matchTypes call by other
SE-0110-related code that bails if the two types do not have the same
"parenness".

Fixes rdar://problem/33043106 / SR-5387.
2017-07-10 17:36:53 -07:00
Mark Lacey
b89b5707b2 Revert "[QoI] Add a fixed crasher which triggers closure return diagnostics related to rdar://problem/33067102"
This reverts commit 70deaa89e2.

My next commit already added the same test case, but this reverted
commit added it in a way that the test will fail with my fix in place.
2017-07-10 17:36:37 -07:00
Pavel Yaskevich
70deaa89e2 [QoI] Add a fixed crasher which triggers closure return diagnostics related to rdar://problem/33067102 2017-07-10 16:08:14 -07:00
Pavel Yaskevich
be204f27d2 Merge pull request #10779 from xedin/rdar-33135487
[QoI] Don't try to lookup members on incorrect type while diagnosing keypath components
2017-07-06 10:04:42 -07:00
swift-ci
9fb11c5dd0 Merge pull request #10787 from DougGregor/gsb-nested-in-concrete 2017-07-05 23:32:31 -07:00
Doug Gregor
1c6c51d137 [GSB] Cope with elided conformance requirements in concrete nested types.
If we encounter an associated type reference within a concrete type, but
haven't seen a specific protocol requirement, add the protocol
conformance.

Fixes rdar://problem/33139928 and another crasher.
2017-07-05 23:08:41 -07:00
Pavel Yaskevich
c45073efd1 [QoI] Don't try to lookup members on incorrect type while diagnosing keypath components
While trying to diagnose problems related to keypath components
don't assume that type of the component is always correct, check
before trying to see if it's bridged type or has members.

Resolves: rdar://problem/33135487
2017-07-05 17:19:05 -07:00
Jordan Rose
88556eec94 Avoid building conformance lookup tables when we don't have to.
- Deinitializers never get a custom Objective-C name.
- Classes and protocols are never bridged themselves; that only matters
  for structs and enums.

This avoids another circularity issue like the one in a8bc132565,
where the Clang importer ends up importing a class and hands it to the
type checker, which then asks about conformances. The conformance
lookup table goes to add the extension from the Swift module, except
that the Swift module is what asked for the import in the first place.

It's possible there's a more general solution here, but this
particular change is good even in the non-crashy cases, and definitely
safe for Swift 4.0. Even if the test case is even more idiosyncratic
than the last one.

The test case change for SourceKit is probably due to the first
category not triggering the import of the other two
categories. Changes in import order have been known to affect source
compatibility, though not frequently. However, categories are not
intended to be ordered in the first place. There's still more we can
do in this space, and implicitly depending on these calls /outside/ of
the importer to control category import order was quite brittle
anyway.

SR-5330 / rdar://problem/32677610
2017-07-05 11:23:27 -07:00
swift-ci
c063d4939f Merge pull request #10714 from DougGregor/gsb-no-unresolved-potential-archetypes 2017-06-30 09:51:18 -07:00
Pavel Yaskevich
a82b16fb2d [QoI] Don't assume that contextual type is always present for trailing closure diagnostics
Fixes crasher in diagnostics related to the fact that contextual type
is not always available when trying to diagnose problems related to
calls with trailing closures.

Resolves: rdar://problem/33067102
2017-06-29 23:09:55 -07:00
Doug Gregor
ac8e8aa1b3 [GSB] Stop creating unresolved potential archetypes; rework typo correction.
The small-but-significant change to the generic signature builder is
to refuse to create unresolved potential archetypes. Instead, delay
any requirement that depends on such type, to be reprocessed once
we've seen all of the other requirements. If the type can be resolved
later, it will be; Otherwise, the type checker will complain when it
sees an unresolvable type. By itself, this fixes the crash in SR-2796.

Doing this by itself regresses diagnostics because typo correction in
the generic signature builder no longer kicks in. Therefore, implement
typo correction for these cases in the type checker proper, using its
existing facilities for typo correction. The result is more consistent
code with a better result.

Fixes SR-2796 / rdar://problem/28544316.
2017-06-29 16:52:46 -07:00
Doug Gregor
c1cb8eb9a2 Reinstate crasher from SR-4737 / rdar://problem/31905232.
It was failing to crash for the wrong reasons; this needs more work
(and a proper reduction).
2017-06-28 09:41:06 -07:00
Doug Gregor
6862ef10ac Add recently-fixed test case from SR-4737 / rdar://problem/31905232. 2017-06-23 22:29:47 -07:00
Doug Gregor
dd3869739e [GSB] Don't add invalid concrete requirements.
When a concrete requirement is invalid due to the concrete type
lacking a conformance to a particular, required protocol, don't emit
that incorrect requirement---it causes invalid states further down the
line.

Fixes SR-5014 / rdar://problem/32402482.

While here, fix a comment that Huon noticed trailed off into oblivion.
2017-06-23 22:23:46 -07:00
Doug Gregor
2f00a08b85 Add formerly-crashing test case for SR-4786 / rdar://problem/31955862. 2017-06-23 22:17:58 -07:00
Doug Gregor
c47aea7150 [GSB] Cope with typealiases within protocol hierarchies.
When we see two type(aliase)s with the same name in a protocol
hierarchy, make them equal with an implied same-type requirement. This
detects inconstencies in typealiases across different protocols, and
eliminates the need for ad hoc consistency checking. This is a step
toward simplifying away the need for direct-diagnosis operations
involving concrete type mismatches.

While here, warn when we see an associated type with the same as a
typealias from an inherited protocol; in this case, the associated
type is basically useless, because it's going to be equivalent to the
typealias.
2017-06-23 17:25:45 -07:00
Doug Gregor
52e52b564b [GSB] Improve handling of conformances resolved by concrete types.
Centralize and simplify the handling of conformance requirements
resolved by same-type-to-concrete requirements in a few ways:

* Always store a ProtocolConformanceRef in via-superclass and
  via-concrete requirement sources, so we never lose this information.

* When concretizing a nested type based on its parent, use the
  via-concrete conformance information rather than performing lookup
  again, simplifying this operation considerably and avoiding
  redundant lookups.

* When adding a conformance requirement to a potential archetype that
  is equivalent to a concrete type, attempt to find and record the
  conformance.

Fixes SR-4295 / rdar://problem/31372308.
2017-06-23 09:34:57 -07:00
Slava Pestov
a2181092fb AST: Tweak a concrete-nested-type-of-archetype hack slightly
When an archetype conforms to a protocol abstractly (ie, it is
not class-constrained and we don't have any further information
other than that it conforms), we can recover nested types,
but we cannot recover the conformance of those nested types
to protocols if those conformances are concrete (the nested
type might be concrete, or it might be a class-constrained
archetype).

To work around this, we added a hack where if the conformance
lookup in the SubstitutionMap fails, we fall back to the module.

This is horrible and unprincipled, but has to remain in place
until more infrastructure is plumbed through.

Commit 620db5f74c made this
workaround apply in fewer cases, so that we could still catch
cases where the SubstitutionMap was constructed with missing
conformances.

Unfortunately this workaround didn't handle the case where the
nested type was an archetype with a superclass constraint.

This will all go away soon, but for now tweak the logic a bit,
since I really want to keep the "narrow" workaround in place
and not the general fallback, otherwise we run the risk of
SubstitutionMap conformance lookup bitrotting completely.

Fixes <https://bugs.swift.org/browse/SR-4088> and
<rdar://problem/32773028>.
2017-06-20 22:18:50 -07:00
Doug Gregor
fe7ba8b79b [GSB] Pull typo correction for nested types into delayed reqs handling.
Rather than performing typo correction at the very end of finalize(),
do it as part of delayed requirement handling when we cannot otherwise
make progress. This is a cleaner way to cope with typo correction that
gives us a better chance of getting to a sane result.

Fixes rdar://problem/31048352 by eliminating the need for tracking the
number of unresolved potential archetypes altogether. Fixes
rdar://problem/32077627.
2017-06-19 22:47:33 -07:00
Doug Gregor
b44f24dc2d [Type checker] Re-validate typealiases in protocols after protocol validation.
Validation for typealiases in protocols is... odd. It needs to avoid
depending on the whole protocol being validated, so it does an initial
validation that can leave nested types of Self (and other associated
types) somewhat unresolved. In these cases, do something icky but
partially effective: when we resolve the protocol, go back and clean
up the types of these typealiases.

A better solution would allow us to use the types of these typealiases
within the Generic Signature Builder without recording them in the AST
as "the interface type", so there's no way unresolved nested types
could be found (and, therefore, nothing to "fix up" later). Howwever,
that's a more significant undertaking.

Fixes rdar://problem/32287795.
2017-06-15 22:51:30 -07:00
Doug Gregor
01b45a245c Fold ConstraintSolver::coerceToRValue() into TypeChecker::coerceToRValue()
ConstraintSolver::coerceToRValue() missed a bunch of cases where we
should be dealing with lvalues, e.g., tuples, "try" expressions, and
so on. Extend TypeChecker::coerceToRValue() to deal with the
expression type side-tables and ConstraintSolver::coerceToRValue() to
it.

Fixes rdar://problem/32700180, a crash-on-valid.
2017-06-14 22:44:32 -07:00
Slava Pestov
65c3565c2d Sema: Fix failure to produce diagnostics when 'is' casts are involved
When re-typechecking an expression during diagnostics, we begin by
erasing all the types in the expression. However, any expressions
created as part of applying the solution will remain.

CSGen was doing the wrong thing when it encountered EnumIsCaseExpr,
which can only appear in already-type checked ASTs.

Returning expr->getType() is not correct, because the type is not
yet set; returning a null type is intended to signal that a
diagnostic was already emitted, which causes Sema to stop
type checking.

The end result is that certain combinations of invalid code with
an 'is' cast nested inside would crash either the AST verifier
(with asserts on) or in SILGen (with asserts off), because we
would stop trying to diagnose the issue prematurely, and possibly
not emit a diagnostic at all.

Fixes <https://bugs.swift.org/browse/SR-5050> and
<rdar://problem/32487948>.
2017-06-13 20:19:43 -07:00
Slava Pestov
632fdf5dbd Sema: Add a SE-0110-related test case that used to crash 2017-06-05 23:11:53 -07:00
Robert Widmann
71bf312a25 Migrate the rest of the tests to %empty-directory 2017-06-04 11:08:39 -07:00
Slava Pestov
945f6cfeb1 Add a fixed crasher and an unfixed one 2017-06-02 20:43:27 -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
9c1e9756e4 Merge pull request #9971 from xedin/sr-4301
[QoI] Fix crash when constructing existential metatype without '.init'
2017-05-29 23:16:45 -07:00
Pavel Yaskevich
29b8f5615d [QoI] Fix crash when constructing existential metatype without '.init'
Resolves: SR-4301.
2017-05-29 22:08:50 -07:00
Slava Pestov
7af399fd51 Sema: Change a getInterfaceType() to hasInterfaceType() in a couple of places
ValueDecl::getInterfaceType() asserts if the decl has no interface
type; to check if the declaration has been type checked yet, use
hasInterfaceType().

Fixes <https://bugs.swift.org/browse/SR-4743>.
2017-05-29 00:06:55 -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
a3ff37c1ad Add an unfixed crasher and two fixed ones 2017-05-23 23:14:10 -07:00
Slava Pestov
e4b08e00a2 Add a regression test 2017-05-22 18:35:52 -07:00
Slava Pestov
e58ae766a3 Fix and un-XFAIL regressed crashers from recent stdlib change 2017-05-17 05:51:51 -07: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
Doug Gregor
fd4bcdc007 Add fixed crasher for rdar://problem/30154791. 2017-05-11 09:31:58 -07:00
Slava Pestov
a21053d5d2 Add a regression test 2017-05-07 01:57:38 -07:00
Slava Pestov
bf23ed2d18 Add a regression test 2017-05-03 22:31:52 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Doug Gregor
93435d17d6 [Substitution Map] Handle substitutions of generic parameters made concrete.
If SubstitutionMap is asked to form a substitution for a generic
parameter that has been made concrete by the generic signature,
substitute into the concrete type. This allows us to better deal with
non-canonical types.
2017-04-28 16:22:07 -07:00
Doug Gregor
29a15ce402 [Stdlib] Apply SE-0142 to fix ABI FIXME #92, part of ABI FIXME #99. 2017-04-19 23:15:33 -07:00
Slava Pestov
60998cbb50 Merge pull request #8842 from slavapestov/new-test
Add a regression test
2017-04-18 14:58:47 -07:00