Commit Graph

161 Commits

Author SHA1 Message Date
Rintaro Ishizaki
01b8fbc1bf [CodeCompletion] Implement .Type completion in expression context
rdar://problem/22072865
2019-02-12 10:40:08 -08:00
Slava Pestov
7d33177b84 LookupVisibleDecls: Don't use getReasonForSuper() for members of protocols and superclass constraints on an archetype
Semantically, these are not superclass/refined-protocol members.
If I have a generic parameter <T : P & Q>, then when looking at
a value of type T, members of P and Q are at the same "level" as
if I had a value of type (P & Q).
2019-01-08 00:14:52 -05:00
Slava Pestov
ac04679f0c AST: Change TypeBase::addCurriedSelfType() to use the self type not declared type
In a protocol, the overload signature type of a property is (Self) -> (),
not (Proto) -> ().
2019-01-08 00:14:52 -05:00
Slava Pestov
0e458900b1 Sema: Remove hack introduced by 31245556
It looks like Type::subst() was subsequently fixed for GenericFunctionTypes
in 06d16795 so we can remove this hack.
2019-01-08 00:14:52 -05:00
Rintaro Ishizaki
c84ea2b281 [CodeCompletion] Improve context type analysis for overloaded method
For:

    class MyClass {
        func foo(x: SomeType)
        func foo(x: OtherType)
    }

    func test(obj: MyClass) {
        obj.foo(x: <HERE>)
    }

Type checker doesn't keep overloaded choices for 'obj.foo' in the AST
after typechecking. Code completion need to lookup members to collect
possible parameter types.
2018-10-30 09:02:00 +09:00
Rintaro Ishizaki
1155adeef1 [Parse] Remove special handling for .<keyword><code-complete> (#18869)
At the time this logic was introduced in 8f83ca67, `<expr>.<keyword>` wasn't
allowed. Now that SE-0071 has been implemented, this logic doesn't provide any
positive effects.
2018-08-22 13:37:08 +09:00
Huon Wilson
b96aedaf64 [Sema] Match Swift 4.0/4.1 overloading behaviour for properties in extensions of generic types.
The patch that nailed down our semantics here missed an additional case that
required a compatibility hack: a property on a generic type and a same-named one
in an (unconstrained) extension:

    struct Foo<T> {
        var x: Int { return 0 }
    }
    extension Foo {
        var x: Bool { return false }
    }

Fixes rdar://problem/40685642.
2018-06-22 08:43:34 +10:00
Slava Pestov
4051246932 Merge pull request #16811 from AnthonyLatsis/code-compl-dup-restated-requirements
[CodeCompletion] Duplicate existential requirements when restated
2018-06-15 14:46:26 -07:00
fischertony
ef11b11692 restore completion results order stability 2018-06-09 13:54:01 +03:00
fischertony
3d3f125d28 restore 'public' 2018-06-08 09:54:39 +03:00
fischertony
addc4341af Merge branch 'master' into code-compl-dup-restated-requirements 2018-06-07 08:03:21 +03:00
fischertony
45c9038d0f corrections and review amendments 2018-05-31 19:13:50 +03:00
fischertony
873700fc31 pull remote amendments 2018-05-25 20:22:55 +03:00
fischertony
290715e73e update tests 2018-05-25 20:17:00 +03:00
fischertony
59669a8974 merge to get self completion updates 2018-05-25 20:00:45 +03:00
Anthony Latsis
72b3f85341 Update complete_value_expr.swift 2018-05-25 03:29:07 +03:00
fischertony
079aec35ba [CodeCompletion] Remove static member completions from metatypes 2018-05-25 03:18:57 +03:00
Anthony Latsis
f289e46b80 Merge branch 'master' into code-compl-dup-restated-requirements 2018-05-25 01:10:25 +03:00
fischertony
6c13eba3fd Review amendments & fixed gen sig overload 2018-05-25 00:10:42 +03:00
fischertony
ede3ba207b [CodeCompletion] Duplicate existential requirements when restated 2018-05-24 03:54:05 +03:00
fischertony
7b41a41fb6 updated tests & added completions for postfixExpr 2018-05-12 09:05:57 +03:00
Hamish
dee1590ae2 [Sema] Fix several redeclaration checking bugs
Currently we only give subscripts and var decls custom overload types if they're in generic extensions. However, because we give them no custom overload type in any other case, we don't detect for example a conflict with a previous declaration in the body of the extended type.

This commit changes the overload type logic such that properties and subscripts are always given custom overload types, which is determined by:

- The interface type of the decl (for subscripts only; as variables cannot be overloaded by type)
- The 'self' type of the context, if any
- The generic signature of the context, if any

Additionally, this commit adds a new `swift::conflicting` overload to ensure that different declarations always conflict even if their overload types are different.

Resolves SR-7249, SR-7250 & SR-7251.
2018-03-22 11:42:29 +00:00
Pavel Yaskevich
c0f5711ee5 [ConstraintSystem] Don't apply types to expressions until solution is found
Resolves: rdar://problem/36744895
2018-02-13 00:08:45 -08:00
Mark Lacey
f08823757a IUO: Generate Optional<T> rather than ImplicitlyUnwrappedOptional<T>.
Stop creating ImplicitlyUnwrappedOptional<T> so that we can remove it
from the type system.

Enable the code that generates disjunctions for Optional<T> and
rewrites expressions based on the original declared type being 'T!'.

Most of the changes supporting this were previously merged to master,
but some things were difficult to merge to master without actually
removing IUOs from the type system:
- Dynamic member lookup and dynamic subscripting
- Changes to ensure the bridging peephole still works

Past commits have attempted to retain as much fidelity with how we
were printing things as possible. There are some cases where we still
are not printing things the same way:
- In diagnostics we will print '?' rather than '!'
- Some SourceKit and Code Completion output where we print a Type
  rather than Decl.

Things like module printing via swift-ide-test attempt to print '!'
any place that we now have Optional types that were declared as IUOs.

There are some diagnostics regressions related to the fact that we can
no longer "look through" IUOs. For the same reason some output and
functionality changes in Code Completion. I have an idea of how we can
restore these, and have opened a bug to investigate doing so.

There are some small source compatibility breaks that result from
this change:
- Results of dynamic lookup that are themselves declared IUO can in
  rare circumstances be inferred differently. This shows up in
  test/ClangImporter/objc_parse.swift, where we have
    var optStr = obj.nsstringProperty
  Rather than inferring optStr to be 'String!?', we now infer this to
  be 'String??', which is in line with the expectations of SE-0054.
  The fact that we were only inferring the outermost IUO to be an
  Optional in Swift 4 was a result of the incomplete implementation of
  SE-0054 as opposed to a particular design. This should rarely cause
  problems since in the common-case of actually using the property rather
  than just assigning it to a value with inferred type, we will behave
  the same way.
- Overloading functions with inout parameters strictly by a difference
  in optionality (i.e. Optional<T> vs. ImplicitlyUnwrappedOptional<T>)
  will result in an error rather than the diagnostic that was added
  in Swift 4.1.
- Any place where '!' was being used where it wasn't supposed to be
  allowed by SE-0054 will now treat the '!' as if it were '?'.
  Swift 4.1 generates warnings for these saying that putting '!'
  in that location is deprecated. These locations include for example
  typealiases or any place where '!' is nested in another type like
  `Int!?` or `[Int!]`.

This commit effectively means ImplicitlyUnwrappedOptional<T> is no
longer part of the type system, although I haven't actually removed
all of the code dealing with it yet.

ImplicitlyUnwrappedOptional<T> is is dead, long live implicitly
unwrapped Optional<T>!

Resolves rdar://problem/33272674.
2018-01-31 12:15:58 -08:00
Doug Gregor
8b58b0dbb4 [Type checker] Make redeclaration checking validate fewer declarations.
Redeclaration checking was validating all declarations with the same
base name as the given declaration (and in the same general nominal
type), even when it was trivial to determine that the declarations
could not be conflicting. Separate out the easy structural checks
(based on kind, full name, instance vs. non-instance member, etc.) and
perform those first, before validation.

Fixes SR-6558, a case where redeclaration checking caused some
unnecessary recursion in the type checker.
2017-12-30 23:27:04 -08:00
Ben Langmuir
642ae90a86 [code-complete] Reduce the priority of function call patterns
Constructor call patterns already get a real priority, but because of
the way we do function call patterns we don't have enough information,
and previously we were setting it to "expression specific", which is
unnecessarily high, particularly since functions (unlike inits) have
other better ways to code-complete already.

rdar://31113161
2017-12-18 12:55:20 -08:00
Ben Langmuir
b6d5a1f1a5 [code-complete] Do not insert rparen after a call pattern completion
When completing
  Foo(<here>
We will now provide
  bar: <#value#>
instead of
  bar: <#value#>)

Inserting the rparen caused some problems in practice:
* the old behaviour optimized for typing Foo(<complete> instead of
  Foo(<complete>), which can conflict with user behaviours or ...
* in editors with automatic brace-matching, we often conflicted with the
  editor, leading to extraneous closing parens

And in general, it is much more predictable for tooling to either insert
matching ( and ) or to not insert either.  While this change may not be
ideal For users of editors that do not do automatic brace-matching, I
believe it is still better overall to have to type a missing paren than
to have to delete an extraneous one.

rdar://31113161
2017-12-18 11:59:49 -08:00
Ben Langmuir
93956eb34b [code-complete] Put call-pattern heuristics under a flag
The original hope was we could make these heuristics really good, but
since that is not currently in sight (and may never be), we want to be
able to turn them off.  For now, just plumb through an internal flag to
control the behaviour.  A future change will customize the behaviour in
SourceKit.

rdar://31113161
2017-12-15 13:23:44 -08:00
Michael Ilseman
a7b299b51b [tests] Update tests as String.CharacterView is deprecated 2017-08-11 12:32:39 -07:00
Robert Widmann
b8069fbd8d Update tests to remove @autoclosure in decl position
Also restore some diagnostics in TypeCheckType that should have
migrated with the attributes.  In particular, diagnose cases where
we have @autoclosure with any function type repr with a non-Void
input type.

Resolves SR-5296
2017-07-05 22:09:19 -07:00
Pavel Yaskevich
f09d2ad397 [ConstraintSolver] Forbid forming solutions with free generic type parameters
`FreeTypeVariableBinding::GenericParameters` mode allowed to bind
all free type variables with fresh generic parameter types, which
is incorrect (at least) if there are multiple generic solutions
present, because such parameters couldn't be compared.

This mode was used for code completion, which is now switched to use
`FreeTypeVariableBinding::UnresolvedType` instead.
2017-06-01 14:05:05 -07:00
Doug Gregor
9ff7ff73ef Fix up order-dependent test cases 2017-05-15 22:17:19 -07:00
Max Moiseev
8e83ac3220 Adjusting the tests to the new StringProtocol 2017-05-01 16:41:26 -07:00
Max Moiseev
ec8e286b5c Merge branch 'master' into new-integer-protocols 2017-03-24 14:14:00 -07:00
Doug Gregor
537971e77a [AST] Teach OverrideFilteringConsumer not to substitute into generic function types.
Substitution into a generic function type produces non-canonical
generic signatures. This functionality should either be removed or be
completely rewritten to properly use the GenericSignatureBuilder. For
now, disable this one client's unsafe use of it.

This does regression code-completion results slightly, where we were
depending on OverrideFilteringConsumer's behavior to filter out some
redundant results. I've captured the work to fix this properly in
rdar://problem/31245556.
2017-03-24 11:36:44 -07:00
Max Moiseev
835b8809d2 Merge branch 'master' into new-integer-protocols 2017-03-07 16:18:54 -08:00
Slava Pestov
6a9abafbc7 Sema: Subscripts in generic contexts should have a GenericFunctionType
Fixes <rdar://problem/22086900>.
2017-02-21 23:52:13 -08:00
Max Moiseev
a167238d1d Fixing more tests 2017-01-12 15:54:56 -08:00
Slava Pestov
a4afb993f1 AST: Make Type::transform() more robust with ParenTypes
There is never any reason for a transform to treat a ParenType
differently from the underlying type itself. Calling the given
function with ParenTypes is a source of bugs where they get
desugared on accident. Make transform() skip the function
entirely for ParenTypes, and remove a spot where we were
checking explicitly.
2016-12-12 21:10:07 -08:00
Slava Pestov
4ebac86895 AST: Type::subst(): try harder to preserve sugar
If a sugared type desugars to a substitutable type, we would
return the replacement type without the sugar. I think in
practice this meant that ParenType would be lost sometimes.

Preserving this correctly is required for an upcoming CSDiag
change.

Note that there's a minor source-breaking change with enum
case constructors here. I've filed <rdar://problem/27261929>
to track sorting it out in Swift 3 mode.

Also an upcoming patch fixes another related issue and adds more
tests for case constructors.
2016-11-29 03:05:28 -07:00
Slava Pestov
cfe9e6a3de IDE: Use GenericSignatures and interface types (mostly)
There was a ton of complicated logic here to work around
two problems:

- Same-type constraints were not represented properly in
  RequirementReprs, requiring us to store them in strong form
  and parse them out when printing type interfaces.

- The TypeBase::getAllGenericArgs() method did not do the
  right thing for members of protocols and protocol extensions,
  and so instead of simple calls to Type::subst(), we had
  an elaborate 'ArchetypeTransformer' abstraction repeated
  in two places.

Rewrite this code to use GenericSignatures and
GenericFunctionType instead of old-school GenericParamLists
and PolymorphicFunctionType.

This changes the code completion and AST printer output
slightly. A few of the changes are actually fixes for cases
where the old code didn't handle substitutions properly.
A few others are subjective, for example a generic parameter
list of the form <T : Proto> now prints as <T where T : Proto>.

We can add heuristics to make the output whatever we want
here; the important thing is that now we're using modern
abstractions.
2016-10-02 23:49:15 -04:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Argyrios Kyrtzidis
8b1dde645a [IDE] Fix code-completion fallout after changes for SE-0111.
rdar://27642873
2016-08-09 18:07:58 -07:00
Argyrios Kyrtzidis
f3074aa3d2 [test/IDE] Remove test cases that use the old and removed function curry syntax. NFC. 2016-08-09 18:07:58 -07:00
Doug Gregor
5b67fe455c [SE-0111 HACK] Disable some IDE- and SourceKit-related changes.
I still need to investigate what happened here, but I don't want it to
delay landing the bulk of SE-0111.
2016-07-29 17:28:25 -07:00
Joe
a6dad0091b [SE-0095] Initial parsing implementation for '&' composition syntax
This commit defines the ‘Any’ keyword, implements parsing for composing
types with an infix ‘&’, and provides a fixit to convert ‘protocol<>’

- Updated tests & stdlib for new composition syntax
- Provide errors when compositions used in inheritance.
Any is treated as a contextual keyword. The name ‘Any’
is used emit the empty composition type. We have to
stop user declaring top level types spelled ‘Any’ too.
2016-07-19 12:01:02 -07:00
Ben Langmuir
1c00cd9637 [CodeCompletion] Fix dot completion with non-nominals
Completion after dot inside an init (or any other parent expr with a
nominal type) was incorrectly looking at the types of parent expressions
whenever the base type was not a nominal (even an lvalue of a nominal
wasn't working).  This code to look at the type of the parent was never
correct, and fortunately the type-checking issues that prompted it to be
added in the first place have since been fixed, so we can just delete
it.

rdar://problem/25773358
2016-06-21 15:12:22 -07:00
Doug Gregor
e2632c1cfa [Code completion] Teach code completion to use declarations for postfix completions.
Code completion had the ability to use declarations to provide better
code completion results for postfix completions, e.g., calls to
functions/methods, but it wasn't trying to get these declarations from
anywhere. Now, get these declarations from the solution to the
constraint system.

The impetus for this is to use default-argument information from the
declaration rather than the type, but plumbing this information
through also means that we get proper "rethrows" annotations, covered
by <rdar://problem/21010193>, and more specific completions in a
number of other places.

Fixes <rdar://problem/21010193>.
2016-06-16 11:44:42 -07:00
Slava Pestov
e8abf54a9a Sema: Fixes for protocol typealiases
This is a big refactoring of resolveTypeInContext() which makes
the function clearer to understand by merging various special
cases and generalizing the logic for walking parent and superclass
contexts to cover more cases.

This improves typealiases in protocols a bit:

1) Previously a typealias in a protocol either had to be concrete,
   or consist of a single path of member types from Self, eg
   Self.A.B. Lift this restriction, so we can now write things like

protocol Fireworks {
  associatedtype Exploding
  typealias Exploder = Exploding -> [Exploding]
}

2) Protocol typealiases can now be accessed via qualified lookup
   on concrete types. Getting this working for unqualified lookup
   requires further refactorings which will be in a subsequent
   patch.
2016-06-11 16:24:14 -07:00
Ben Langmuir
a629d668ac [CodeCompletion] Mark deprecated completions as "not recommended"
If a declaration is marked deprecated (but not unavailable) we want to
mark it as "not recommended" so that users know this probably isn't what
you want. We already do something like this in Clang code completions of
deprecated ObjC declarations.

rdar://problem/26335424
2016-05-23 09:25:30 -07:00