Commit Graph

805 Commits

Author SHA1 Message Date
Holly Borla
b871528179 Merge pull request #32524 from OnyekachiSamuel/fix-confusing-protocol-diagnostic
[Diagnostics] Fix Confusing Protocol Diagnostic
2020-07-02 13:01:19 -07:00
Onyekachi Ezeoke
a08f421c1a fix failing tests 2020-07-02 12:09:07 +01:00
Slava Pestov
ffb59e78bb Merge pull request #32610 from slavapestov/regression-test-sr11030
Add regression test for https://bugs.swift.org/browse/SR-11030 / rdar://problem/52266834
2020-06-30 00:50:51 -04:00
Slava Pestov
422fd41396 Sema: Fix assertion when synthesizing Codable with an IUO stored property
Fixes <https://bugs.swift.org/browse/SR-13118>.
2020-06-29 22:27:38 -04:00
Slava Pestov
63bf06d959 Add regression test for https://bugs.swift.org/browse/SR-11030 / rdar://problem/52266834 2020-06-29 22:26:16 -04:00
Slava Pestov
71e267d5b1 GSB: Teach 'derived via concrete' computation about superclass constraints
Under certain circumstances, introducing a concrete same-type or
superclass constraint can re-introduce conformance constraints
which were previously redundant.

For example, consider this code, which we correctly support today:

protocol P {
  associatedtype T : Q
}

protocol Q {}

class SomeClass<U : Q> {}

struct Outer<T> where T : P {
  func inner<U>(_: U) where T == SomeClass<U>, U : Q {}
}

The constraint 'T == SomeClass<U>' makes the outer constraint
`T : P' redundant, because SomeClass already conforms to P.
It also introduces an implied same-type constraint 'U == T.T'.

However, whereas 'T : P' together with 'U == T.T' make 'U : Q'
redundant, the introduction of the constraint 'T == SomeClass<U>'
removes 'T : P', so we re-introduce an explicit constraint 'U : Q'
in order to get a valid generic signature.

This code path did the right thing for constraints derived via
concrete same-type constraints, but it did not handle superclass
constraints.

As a result, this case was broken:

struct Outer<T> where T : P {
  func inner<U>(_: U) where T : SomeClass<U>, U : Q {}
}

This is the same example as above, except T is related via a
superclass constraint to SomeClass<U>, instead of via a concrete
same-type constraint.

The subtlety here is that we must check if the superclass type
actually conforms to the requirement source's protocol, because it
is possible to have a superclass-constrained generic parameter
where some conformances are abstract. Eg, if SomeClass did not
conform to another protocol P2, we could write

func foo<T, U>(_: T, _: U) where T : SomeClass<U>, T : P2 {}

In this case, 'T : P2' is an abstract conformance on the type 'T'.

The common case where this would come up in real code is when you
have a class that conforms to a protocol with an associated type,
and one of the protocol requirements was fulfilled by a default in
a protocol extension, eg:

protocol P {
  associatedtype T : Q

  func foo()
}

extension P {
  func foo() {}
}

class ConformsWithDefault<T : Q> : P {}

The above used to crash; now it will type-check correctly.

Fixes <rdar://problem/44736411>, <https://bugs.swift.org/browse/SR-8814>..
2020-06-21 23:42:10 -04:00
Slava Pestov
989f4e119f Add regression test for https://bugs.swift.org/browse/SR-1329 2020-06-19 16:32:05 -04:00
Suyash Srijan
b61b68d387 [AST] Look through try expressions inside open existential expression's sub expression in 'getUnwrappedCurryThunkExpr()' (#32458) 2020-06-19 03:29:25 +01:00
Luciano Almeida
59add19684 Merge pull request #32056 from LucianoPAlmeida/minor-typos
[NFC][test] Minor typo corrections on test messages
2020-06-17 07:14:27 -03:00
Luciano Almeida
d22821e18b Merge pull request #31814 from LucianoPAlmeida/SR-12723-conventions
[SR-12723][Sema] Validate function type param representations thick-to-thin conversions
2020-06-15 21:31:04 -03:00
Suyash Srijan
8573d70e47 [Typechecker] Diagnose use of magic literals as raw value for enum case (#32364) 2020-06-16 00:47:58 +01:00
Suyash Srijan
15643777df [CS] Update splice logic in simplifyLocator to handle situations where the index expression isn't a tuple or paren expression (#32356) 2020-06-13 03:28:57 +01:00
Robert Widmann
6ab29cbe4e Introduce NeverNullType to Assert resolveType Never Returns the null Type 2020-06-11 13:00:21 -07:00
Luciano Almeida
d6bf34e65c [CSSimplify] Thin to thin is also allowed 2020-06-08 20:36:09 -03:00
Luciano Almeida
bacbc574a7 [tests] Adding silgen validation tests for SR-12723 to ensure that certain representation convertions do not crash 2020-06-08 20:36:09 -03:00
Luciano Almeida
6d3f53a417 [NFC][test] Minor corrections on test messages 2020-06-05 06:36:09 -03:00
Slava Pestov
4f87899f9f Add regression test for rdar://54394068 2020-06-02 00:49:57 -04:00
Slava Pestov
bc939d7984 Add regression test for https://bugs.swift.org/browse/SR-7002 2020-06-02 00:49:57 -04:00
Suyash Srijan
f026c61dce [ConstraintSystem] Disallow use of enum case as a key path component (#31969) 2020-05-22 20:41:45 +01:00
Slava Pestov
653fa07260 GSB: Fix maybeResolveEquivalenceClass() with member type of superclass-constrained type
Name lookup might find an associated type whose protocol is not in our
conforms-to list, if we have a superclass constraint and the superclass
conforms to the associated type's protocol.

We used to return an unresolved type in this case, which would result in
the constraint getting delayed forever and dropped.

While playing wack-a-mole with regressing crashers, I had to do some
refactoring to get all the tests to pass. Unfortuanately these refactorings
don't lend themselves well to being peeled off into their own commits:

- maybeAddSameTypeRequirementForNestedType() was almost identical to
  concretizeNestedTypeFromConcreteParent(), except for superclasses
  instead of concrete same-type constraints. I merged them together.

- We used to drop same-type constraints where the subject type was an
  ErrorType, because maybeResolveEquivalenceClass() would return an
  unresolved type in this case.

  This violated some invariants around nested types of ArchetypeTypes,
  because now it was possible for a nested type of a concrete type to
  be non-concrete, if the type witness in the conformance was missing
  due to an error.

  Fix this by removing the ErrorType hack, and adjusting a couple of
  other places to handle ErrorTypes in order to avoid regressing with
  invalid code.

Fixes <rdar://problem/45216921>, <https://bugs.swift.org/browse/SR-8945>,
<https://bugs.swift.org/browse/SR-12744>.
2020-05-19 20:28:51 -04:00
Slava Pestov
514a0423b6 GSB: Concretize nested types when adding a superclass constraint
When adding a superclass constraint, we need to find any nested
types belonging to protocols that the superclass conforms to,
and introduce implicit same-type constraints between each nested
type and the corresponding type witness in the superclass's
conformance to that protocol.

Fixes <rdar://problem/39481178>, <https://bugs.swift.org/browse/SR-11232>.
2020-05-15 21:58:58 -04:00
Pavel Yaskevich
d111f119d8 [ConstraintSystem] Detect and diagnose inability to infer type of closure parameter(s)
Detect situation when it's impossible to determine types for
closure parameters used in the body from the context. E.g.
when a call closure is associated with refers to a missing
member.

```swift
struct S {
}

S.foo { a, b in } // `S` doesn't have static member `foo`

let _ = { v in } // not enough context to infer type of `v`

_ = .foo { v in } // base type for `.foo` couldn't be determined
```

Resolves: [SR-12815](https://bugs.swift.org/browse/SR-12815)
Resolves: rdar://problem/63230293
2020-05-15 01:14:30 -07:00
Holly Borla
0c49bb9201 [NFC] Fix validation-test/compiler_crashers_2_fixed/sr11637.swift invocation 2020-04-17 10:31:17 -07:00
Roopesh Chander
abaf79d198 [Property wrappers] Move sr11637 compiler crasher to fixed directory 2020-04-14 13:49:57 -07:00
Slava Pestov
5f51546480 Sema: Fix source range for curry thunks
Fixes <rdar://problem/61117301> / <https://bugs.swift.org/browse/SR-12496>.
2020-04-03 23:26:04 -04:00
Slava Pestov
d7d7e2d2ec Add test case for rdar://problem/60081992 2020-03-24 01:29:26 -04:00
Holly Borla
fce8738ea8 [ConstraintSystem] Replace dependent member types with holes when the base type
doesn't conform to the associatedtype's protocol (only in diagnostic mode).

This allows the solver to find solutions for more cases involving requirement
failures for dependent member types without special cases across the solver
that check for dependent member types with no type variables.
2020-03-03 15:45:24 -08:00
Pavel Yaskevich
df21cbf85c [ConstraintSystem] Ignore attempt to bind type var to dependent member with incorrect base
Just like in cases where both sides are dependent member types
with resolved base that can't be simplified to a concrete type
let's ignore this mismatch and mark affected type variable as a hole
because something else has to be fixed already for this to happen.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
ae79b0d0bd [CSApply] Always use String type for ObjC interop key path
If it's possible to build an Objective-C key path for key path
expression make sure that its implicitly generated string literal
expression has a `String` type.

Resolves: rdar://problem/57356196
2020-02-15 00:04:09 -08:00
Slava Pestov
134cab6156 Add regression test for https://bugs.swift.org/browse/SR-9225 2020-02-07 20:33:54 -05:00
Robert Widmann
88d6559722 [GSB] Map invalid subject types in requirement constraints to ErrorType
Resolves SR-12072 and rdar://58941114
2020-01-28 10:15:43 -08:00
Pavel Yaskevich
8bcc192591 [Diagnostics] Diagnose inability to infer (complex) closure return type 2019-12-19 12:16:30 -08:00
Suyash Srijan
f8dace593c [Typechecker] Fix a crash related to use of invalid @autoclosure parameter 2019-12-17 03:24:09 +00:00
Doug Gregor
f19ca59317 Merge pull request #28449 from DougGregor/sr11599-testcase
[Test] Add already-fixed test from SR-11599 / rdar://problem/56190608
2019-12-05 13:39:10 -08:00
Slava Pestov
8b112232f1 Add regression test for https://bugs.swift.org/browse/SR-4571 2019-12-05 08:45:55 -05:00
swift-ci
19395d6a4d Merge pull request #28446 from DougGregor/rdar57040259 2019-12-02 18:33:39 -08:00
Hamish Knight
19e199e567 Use DefaultArgumentExpr for caller-side defaults (#28279)
Use DefaultArgumentExpr for caller-side defaults
2019-12-02 13:57:17 -08:00
Doug Gregor
929edd3cb3 [Test] Add already-fixed test from SR-11599 / rdar://problem/56190608 2019-11-22 16:14:04 -08:00
Doug Gregor
c4ed40dc15 [Type checker] Fix crash with invalid overriding property.
When an overriding property containing willSet or didSet is not within
a type, the type checker could crash due to a missing "self"
declaration. Check this condition. Fixes rdar://problem/57040259.
2019-11-22 15:38:05 -08:00
Robert Widmann
c83c0f4cb7 Filter out invalid nested types from typealias override checking
The lookupDirect means that we can see type declarations nested inside of a protocol. If we do not filter these invalid declarations, we will offer a bogus fixit on top of a cycle diagnostic.  Remove these types from consideration entirely so we don't crash and don't offer bogus fixits.

Resolves rdar://57003317
2019-11-20 15:17:09 -08:00
Hamish Knight
c667d2b361 Use DefaultArgumentExpr for caller-side defaults
This commit changes how we represent caller-side
default arguments within the AST. Instead of
directly inserting them into the call-site, use
a DefaultArgumentExpr to refer to them indirectly.

The main goal of this change is to make it such
that the expression type-checker no longer cares
about the difference between caller-side and
callee-side default arguments. In particular, it
no longer cares about whether a caller-side
default argument is well-formed when type-checking
an apply. This is important because any
conversions introduced by the default argument
shouldn't affect the score of the resulting
solution.

Instead, caller-side defaults are now lazily
type-checked when we want to emit them in SILGen.
This is done through introducing a request, and
adjusting the logic in SILGen to be more lenient
with ErrorExprs. Caller-side defaults in primary
files are still also currently checked as a part
of the declaration by `checkDefaultArguments`.

Resolves SR-11085.
Resolves rdar://problem/56144412.
2019-11-20 15:07:32 -08:00
Slava Pestov
fb581fdc8f Add a regression test for https://bugs.swift.org/browse/SR-10612 2019-11-18 18:26:03 -05:00
Slava Pestov
0e06792642 Add regression test for SR-10201 2019-11-14 18:26:52 -05:00
Slava Pestov
686ddd7cf7 Sema: Tighten up getReferencedAssociatedTypes()
If a protocol requirement has a type that's a nested member
type of another member type, eg,

protocol P {
  associatedtype A : Q
  func f(_: A.B)
}

Then we don't actually want to use 'f()' to infer the witness
for 'A'. By avoiding doing so, we eliminate some cycles which
can allow some programs to type check that didn't before.
2019-11-13 23:42:08 -05:00
Slava Pestov
e35a068265 Sema: Add test case for https://bugs.swift.org/browse/SR-11392 2019-11-13 23:42:08 -05:00
Suyash Srijan
7e1ed77a9e Merge pull request #28099 from theblixguy/fix/SR-10937
[PropertyWrappers] Fix a crash when using multiple wrappers of the same type
2019-11-08 10:52:15 +00:00
Slava Pestov
88cbcea325 Add a regression test for SR-8469 / rdar://43888895 2019-11-07 22:59:07 -05:00
Suyash Srijan
a2d0bf6f9c [PropertyWrappers] When finding the initial value for the property, properly handle the situation where we have multiple attached property wrappers
If a property has multiple property wrappers attached, we'll have multiple nested calls, where each call's argument is a call to construct the next wrapper in the chain. However, when we use multiple wrappers consecutively, we cannot just rely on the call's type matching the innermost wrapper's type, because it will match the first wrapper in the sequence of consective wrappers and we'll end up crashing in SILGen. So, we should check if the call's argument is another call and look into that before checking the types.
2019-11-07 21:27:52 +00:00
Robert Widmann
c75af38a7a Drop ConformanceContexts out of the TypeChecker 2019-11-06 11:41:03 -08:00
Holly Borla
e63f259f4f [ConstraintSystem] Bind holes to UnresolvedType instead of Any. 2019-11-05 09:15:13 -08:00