Commit Graph

12650 Commits

Author SHA1 Message Date
David Ungar
6ec471e6eb Format 2019-01-17 11:16:39 -08:00
David Ungar
584c157796 WIP move info to KnownProtocols.def, unformatted 2019-01-17 11:15:58 -08:00
Robert Widmann
c5b7230d22 [NFC] Upgrade EnumElementDecl to a DeclContext
Pure plumbing for the sake of default arguments.
2019-01-16 18:39:30 -05:00
Pavel Yaskevich
ffa49969f5 [ConstraintSystem] Mark generic parameter bindings as potentially incomplete by default
This helps to postpone attempting bindings related to generic
parameters with all else being equal.

Consider situation when function has class requirement on its
generic parameter. Without such requirement solver would infer
sub-class for `T`. But currently when requirement is present base
class is inferred instead, because when bindings for such generic
parameter are attempted early single available binding at that
point comes from the requirement.

```swift
class BaseClass {}
class SubClass: BaseClass {}

struct Box<T> { init(_: T.Type) {} }

func test<T: BaseClass>(box: Box<T>) -> T.Type {
  return T.self
}

test(box: .init(SubClass.self)) // `T` expected to be `SubClass`
```

Resolves: [SR-9626](https://bugs.swift.org/browse/SR-9626)
Resolves: rdar://problem/47324309
2019-01-16 14:07:36 -08:00
Pavel Yaskevich
e26fc1efff [ConstraintSystem] Skip literal protocols without default types from minimalization
After collecting possible conformances and types for each argument,
`ArgumentInfoCollector` attempts literal protocol minimalization
to reduce the set of possible types argument could assume. Let's
exclude literal protocols without default types like
`ExpressibleByNilLiteral` from consideration by that algorithm.

Resolves: rdar://problem/47266563
2019-01-16 00:35:17 -08:00
David Ungar
cf3034bd26 Use Request to getDefaultType & move cache to SourceFile. 2019-01-15 23:18:44 -08:00
Pavel Yaskevich
f348fb133e Merge pull request #21864 from xedin/adjust-the-underadjusted-formal-access
[AST] If access control is disabled adjust declaration access to maxi…
2019-01-15 01:29:23 -08:00
Pavel Yaskevich
b78ffa77e8 [AST] If access control is disabled adjust declaration access to maximum openness
This is a follow-up to https://github.com/apple/swift/pull/21783
which made `is{Setter}AccessibleFrom` respect `-disable-access-control`
flag. Now it's `getAdjustedFormalAccess` turn to do the same.
2019-01-14 21:26:11 -08:00
Slava Pestov
6f15193ac3 Merge pull request #21846 from slavapestov/bind-constraint-more
Sema: Use ConstraintKind::Bind where possible instead of ::Equal
2019-01-14 17:56:14 -05:00
Pavel Yaskevich
69c622fc06 Merge pull request #21783 from xedin/rdar-30933988
[AST] `Decl::is*AccessibleFrom` methods should respect access control…
2019-01-14 14:06:44 -08:00
Slava Pestov
e99607c421 Sema: Use ConstraintKind::Bind where possible instead of ::Equal
Solving Bind is a little easier than Equal. The only remaining uses of Equal
are in the .member syntax and keypaths; if we can refactor those, we might be
able to simplify LValue handling in the type checker in general.
2019-01-14 14:55:16 -05:00
Pavel Yaskevich
e320fa79b1 Merge pull request #21833 from theblixguy/fix/SR-9646
[Sema] Look through OpenExistentialExpr in checkIgnoreExpr()
2019-01-13 20:14:32 -08:00
Suyash Srijan
54a53c2286 [sema] Look through OpenExistentialExpr in checkIgnoreExpr() 2019-01-14 01:51:26 +00:00
Slava Pestov
52c1c8caaf Sema: Clean up solving BindParam constraint
- Avoid creating an unnecessary type variable
- Even if both sides are type variables we can solve them if the LHS cannot
  bind to an InOut or the RHS cannot bind to an LValue; in this case the two
  types are identical and we can merge them
2019-01-12 18:03:01 -05:00
Slava Pestov
353b4cc4c4 Sema: Solve Bind constraints involving to two variables of different lvalue-ness
The restriction here only applies to Equal constraints.

Fixes <rdar://problem/45511838>, <https://bugs.swift.org/browse/SR-9068>.
2019-01-12 18:03:01 -05:00
Slava Pestov
33871548b3 Clean up TypeVariableType::Implementation::mustBeMaterializable(), etc 2019-01-12 14:10:11 -05:00
Pavel Yaskevich
ddc2fa415e [AST] NFC: introduce ASTContext::isAccessControlDisabled 2019-01-11 17:30:10 -08:00
Pavel Yaskevich
5426e0df9e [AST] Decl::is*AccessibleFrom methods should respect access control flag
Otherwise integrated REPL and other tools like LLDB would produce
incorrect results or crash.

Resolves: rdar://problem/30933988
2019-01-11 17:30:10 -08:00
Slava Pestov
81c5a67489 Merge pull request #21758 from pschuh/s-1
Rename NameAliasType to TypeAliasType.
2019-01-10 15:20:41 -05:00
Pavel Yaskevich
6791ef3624 Merge pull request #21756 from xedin/rdar-36989788
[Diagnostics] Diagnose missing members via fixes
2019-01-10 10:36:17 -08:00
Slava Pestov
4dfbd8f2cc Sema: Remove some unreachable LValueType checks 2019-01-10 08:44:18 -05:00
Slava Pestov
1026968616 Sema: Remove ConversionRestrictionKind::TupleToTuple 2019-01-10 08:44:18 -05:00
Slava Pestov
28343c9480 Sema: Remove ConversionRestrictionKind::LValueToRValue 2019-01-10 08:44:18 -05:00
Slava Pestov
dab4616bc1 Sema: simplifyRestrictedConstraintImpl() can't form unsolved constraints 2019-01-10 08:44:18 -05:00
Slava Pestov
515ffe9761 Sema: Don't try to solve conversions where one side is a type variable 2019-01-10 08:44:18 -05:00
Slava Pestov
e276b12d9a Sema: Remove unreachable code from CSDiag 2019-01-10 08:44:18 -05:00
Pavel Yaskevich
74a8ee177e [Diagnostics] Diagnose missing members via fixes
Try to fix constraint system in a way where member
reference is going to be defined in terms of its use,
which makes it seem like parameters match arguments
exactly. Such helps to produce solutions and diagnose
failures related to missing members precisely.

These changes would be further extended to diagnose use
of unavailable members and other structural member failures.

Resolves: rdar://problem/34583132
Resolves: rdar://problem/36989788
Resolved: rdar://problem/39586166
Resolves: rdar://problem/40537782
Resolves: rdar://problem/46211109
2019-01-09 17:29:49 -08:00
Parker Schuh
f5859ff46e Rename NameAliasType to TypeAliasType. 2019-01-09 16:47:13 -08:00
Pavel Yaskevich
60fb2bf94e [CSFix] Try to fix missing member by defining it based on use
If lookup couldn't find anything matching given name, let's try to
fake its presence based on how member is being used. This is going
to help (potentially) type-check whole expression and diagnose the
problem precisely.
2019-01-09 14:35:27 -08:00
Pavel Yaskevich
91eec24b62 Merge pull request #21726 from xedin/fix-repl-method-override
[TypeChecker] Don't verify override access control if it has been dis…
2019-01-09 10:27:36 -08:00
Slava Pestov
033321fc32 LookupVisibleDecls: Remove unnecessary resolveExtension() call 2019-01-08 22:58:12 -05:00
Slava Pestov
bb34620bf8 Sema: Validate extension if needed in isExtensionApplied()
We're looking at the generic signature of the extension, so it must
have been validated at this point.

I don't have a test case for this and maybe it never came up, but
nothing forces it to be validated here so let's make it more robust
by doing it explicitly.
2019-01-08 22:58:12 -05:00
Slava Pestov
6e593f1f55 Sema: Remove some unnecessary code from validateDeclForNameLookup() 2019-01-08 22:58:12 -05:00
Slava Pestov
716ac81b3e AST: Cache protocol generic signature in GenericContext::getGenericSignature()
The generic signature of a protocol is simple enough that we can
build it directly when asked. However, be sure to cache it for
future use.
2019-01-08 22:58:12 -05:00
Slava Pestov
f34d2024be Sema: Fix crashes when a call of a closure value is missing a 'try'
Two problems here:

- The InterpolatedString instance variable was not always initialized before
  being checked for null

- In the non-null case, we were assuming the result of CallExpr::getCalledValue()
  was non-null, but it's null if the callee is not a function declaration

Fixes <rdar://problem/46973064>.
2019-01-08 21:42:30 -05:00
Slava Pestov
ea64aa3dec Sema: Add a pretty stack trace entry when checking error handling 2019-01-08 21:42:30 -05:00
Pavel Yaskevich
fc22ba6b59 [TypeChecker] Don't verify override access control if it has been disabled by a flag 2019-01-08 18:13:04 -08:00
Slava Pestov
46dd33aa54 LookupVisibleDecls: Remove an unused variable 2019-01-08 16:51:20 -05:00
Slava Pestov
f7e39447a7 LookupVisibleDecls: Find generic parameters in methods inside extensions
The logic here had diverged from UnqualifiedLookup. One day we'll merge
the two, for now clean it up a bit to match.

Note that all generic parameters now have 'Reason' reported as 'Local'.
I don't believe this really matters.

Fixes <rdar://problem/20530021>.
2019-01-08 16:51:20 -05:00
Slava Pestov
146f1a5ab6 LookupVisibleDecls: Fix duplicate completion results when inheritance is used with protocol conformance
Consider this setup:

protocol Proto {
  func foo() {}
}

class Base : Proto {
  func foo() {}
}

class Derived : Base {
  ...
}

When completing members of a Derived instance, we find both the protocol's
foo() and the base class's foo(). These have the following types:

- Proto.foo: <Self : Proto> (Self) -> () -> ()
- Base.foo: (Base) -> () -> ()

If we simply substitute the base type (Derived) into the type of the protocol
member, we get (Derived) -> () -> (), which is different than the type of
Base.foo, so we get both declarations in the completion list.

Instead, use the 'Self' type for the specific class of the conformance,
which in this case is 'Base' even if we're looking at members of 'Derived'.

Fixes <rdar://problem/21161476>, <https://bugs.swift.org/browse/SR-1181>.
2019-01-08 16:51:20 -05:00
Pavel Yaskevich
91e97a0c8f [Diagnostics] Diagnose ambiguity resulting from subscript operator fix as a missing member
Since the rule is to prioritize names over types, let's diagnose
ambiguous solutions containing subscript operator fix as missing
member and list possible candidates to use.
2019-01-08 12:09:02 -08:00
Pavel Yaskevich
06a7ad63f8 [Diagnostics] Diagnose subscript operator misuse via fixes
Fix to use subscript operator instead of spelled out name helps
to produce a solution, that makes it much easier to diagnose
problems precisely and provide proper fix-its, it also helps to
diagnose ambiguous cases, and stacks up nicely with other errors.
2019-01-08 12:06:40 -08:00
Pavel Yaskevich
f032b9c57c [CSFix] Attempt to replace .subscript(...) with subscript operator
If there are no members named "subscript" available, let's try to
replace it with subscript operator with might be what was intended.
2019-01-08 12:06:40 -08:00
Pavel Yaskevich
5636cd3769 Merge pull request #21697 from xedin/fix-repl-subclass
[TypeChecker] Respect access control flag while validating superclass…
2019-01-08 10:59:14 -08:00
Pavel Yaskevich
65abb49aa7 Merge pull request #21517 from xedin/rdar-38885760
[TypeChecker] Always emit a fallback error if type-check failed witho…
2019-01-08 10:01:34 -08:00
Jordan Rose
4a8f81db2b Special-case diagnostic for when you just need @unknown default (#21695)
This is a new feature of Swift 5 mode, so it deserves at least a
little bit of explanation right in the diagnostic. If you have an
otherwise-fully-covered switch but can't assume the enum is frozen,
you'll now get this message:

    switch covers known cases, but 'MusicGenre' may have additional
    unknown values

Furthermore, if the enum comes from a system header, it looks like
this:

    switch covers known cases, but 'NSMusicGenre' may have additional
    unknown values, possibly added in future versions

...to further suggest the idea that even though your switch is covered
/now/, it might not handle everything in the /future/. This extra bit
is limited to system headers to avoid showing up on C enums defined in
your own project, for which it sounds silly. (The main message is
still valid though, since you can cram whatever you want into a C
enum, and people use this pattern to implement "private cases".)

rdar://problem/39367045
2019-01-08 08:45:23 -08:00
Slava Pestov
fc50e8146e Merge pull request #21705 from slavapestov/bogus-request-layout
Sema: Remove bogus call to requestNominalLayout()
2019-01-08 08:05:06 -05:00
Slava Pestov
9cf1efbe77 Sema: Remove bogus call to requestNominalLayout() 2019-01-08 00:20:18 -05:00
Slava Pestov
3c0206d72e LookupVisibleDecls: Remove RestateFilteringConsumer
It's no longer needed after the previous set of changes, and removing it
fixes a crash.

Fixes <rdar://problem/46853611>.
2019-01-08 00:14:52 -05:00
Slava Pestov
6fd25fd521 LookupVisibleDecls: Process associated types in OverrideFilteringConsumer too 2019-01-08 00:14:52 -05:00