Commit Graph

1365 Commits

Author SHA1 Message Date
Rintaro Ishizaki
66c71d1bf7 [SourceKit] Force print '?' for optional method call in code completion. (#16910)
Calling '@objc optional func' requires '?' or '!' after its name. When
completing method calls for them, 'key.sourcetext' should have '?'
whereas 'key.name' shouldn't.
Note that we deliberately do not use optional type name for
'key.typename'. This is consistent with optional chain '?.<propertyName>'
behavior.

rdar://problem/37904574
2018-05-31 16:06:23 -07:00
fischertony
45c9038d0f corrections and review amendments 2018-05-31 19:13:50 +03:00
fischertony
7ef24b10c9 [SR-7789][Additions]
restore accidentally removed constructors from 'self'
replace illegal direct call completions on dynamic metatypes with .init, except archetypes.
2018-05-30 06:05:04 +03:00
fischertony
927598fbcc [CodeCompletion] Missing init completions for dotExpr
Fixes non-visible inherited convenience initializers
Fixes non-visible initializers from protocol extensions
Fixes visible initializers on dynamic metatypes for postfix and parenPostfix expressions
2018-05-28 05:59:49 +03:00
Ben Langmuir
a90aeca095 Merge pull request #16534 from AnthonyLatsis/self-completion-dot-expr
[CodeCompletion] SR-943 'self' for dot expressions
2018-05-24 14:44:21 -07:00
fischertony
7b41a41fb6 updated tests & added completions for postfixExpr 2018-05-12 09:05:57 +03:00
fischertony
c88e1c983f [CodeCompletion] self for dot expressions
May dot expressions finally have a 'self' completion.
2018-05-11 09:48:53 +03:00
Jordan Rose
18162a3ed0 Revert "AST: Simplify ModuleDecl::forAllVisibleModules()"
This reverts commit 0c32c54e36.
2018-05-03 22:40:37 -06:00
Nathan Hawes
d9ca14203d [code-completion] Don't try to equate/convert GenericTypeParameterTypes computing type relations of completion results
For call argument completion, if the expected type and completion result type are
both GenericTypeParameterTypes, comparing them doesn't make sense we can't account
for their different contexts at this point in the code, and hit assertions in the
constraint solver if we try.

For now, don't attempt to add a type relation for this case.
Resolves rdar://problem/38153332.
2018-04-30 15:12:54 -07:00
Slava Pestov
af875829a7 Merge pull request #16206 from slavapestov/serialization-cleanup
Serialization cleanup
2018-04-27 05:22:40 -07:00
Slava Pestov
0c32c54e36 AST: Simplify ModuleDecl::forAllVisibleModules() 2018-04-26 23:37:16 -07:00
Pavel Yaskevich
57ad592844 [Sema] Switch computeDefaultMap to use AnyFunctionType::getParams() 2018-04-26 17:33:08 -07:00
Rintaro Ishizaki
095623b61c [code-complete] Small refactoring in addImportModuleNames (#15943)
Improves readability.
In the future, we will fix "FIXME: Add user-defined swift modules" based
on this.
2018-04-17 08:24:24 +09:00
David Zarzycki
7174d14dad [Parsing] NFC: metaprogram contextual decl keywords into Attr.def 2018-04-07 18:00:12 -04:00
Robert Widmann
03580d2fe5 Add a parameter list to EnumElementDecl
This models, but does not plumb through, default arguments.
2018-03-28 00:05:56 -04:00
Nathan Hawes
cc027287d7 Merge pull request #15471 from nathawes/rdar38188989-code-completion-assertion-failure-in-getValueExprCompletions
[code-completion] Fix assertion failure in getValueExprCompletions
2018-03-26 13:47:02 -07:00
Nathan Hawes
d4bd291569 [code-completion] Fix assertion failure in getValueExprCompletions
This was caused by two separate issues:

1. If given a function type with an IUO return, it would add function call
completions, set Done=true, and then progress to some logic to add
completions for the unwrapped type of optionals. That code would check if
the corresponding decl has the IUO attribute set and, if it was but couldn't
be unwrapped, assert. For function types, it now early exits after adding
call completions.

2. If given the type of a bound (`blah?.`) or forced (`blah!.`) optional,
the type is non-optional and can't be unwrapped and the decl still has the
IUO so it asserts. Refined the assertion to account for this case.

Resolves rdar://problem/38188989.
2018-03-26 11:12:44 -07:00
Doug Gregor
4797fae933 Merge pull request #15497 from DougGregor/remove-name-alias-type
[AST] Fully replace NameAliasType with the new, sugary-sweet BoundNameAliasType
2018-03-26 09:03:03 -07:00
Sho Ikeda
976c7f9c27 [gardening][IDE] Replace typedef with using 2018-03-26 13:45:36 +09:00
Doug Gregor
b2b69e8abf Rename BoundNameAliasType to NameAliasType.
NameAliasType is dead! Long live NameAliasType!
2018-03-25 21:35:17 -07:00
Doug Gregor
c43f96a855 [AST] Remove now-unused NameAliasType. 2018-03-25 21:35:16 -07:00
Doug Gregor
e82e7ee908 [Type checker] Use BoundNameAliasType for all typealiases.
Rather than relying on the NameAliasType we get by default for references
to non-generic typealiases, use BoundNameAliasType consistently to handle
references to typealiases that are formed by the type checker.
2018-03-25 21:35:16 -07:00
Doug Gregor
bde6401f5b Support BoundNameAliasType everywhere we support NameAliasType.
This doesn't have a specific effect now, because all of these places
are likely to only see NameAliasType, but it is refactoring with the
intent of eliminating NameAliasType entirely.
2018-03-25 20:46:07 -07:00
Slava Pestov
34fd4ae512 AST: Use DeclBaseName::Kind::Constructor
Fixes <rdar://problem/35852727>, <https://bugs.swift.org/browse/SR-1660>,
<https://bugs.swift.org/browse/SR-6557>.
2018-03-16 00:25:56 -07:00
Slava Pestov
615d068d63 Sema: Replace some uses of getBaseIdentifier() with userFacingName() 2018-03-14 22:26:58 -07:00
Slava Pestov
76349a0f87 Squash some unused variable warnings 2018-03-08 17:05:59 -07:00
Sho Ikeda
cea6c03eb2 [gardening] Use !empty() over size() > 0 2018-03-08 09:21:09 +09: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
be8defb29e Rename lookThroughAllAnyOptionalTypes to lookThroughAllOptionalTypes. 2018-02-05 23:59:01 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Harlan
5e02d2a877 Implement #warning and #error (#14048)
* Implement #warning and #error

* Fix #warning/#error in switch statements

* Fix AST printing for #warning/#error

* Add to test case

* Add extra handling to ParseDeclPoundDiagnostic

* fix dumping

* Consume the right paren even in the failure case

* Diagnose extra tokens on the same line after a diagnostic directive
2018-02-03 18:07:05 -05:00
Mark Lacey
3654dcc8fe Remove getImplicitlyUnwrappedOptionalObjectType. 2018-02-03 10:57:11 -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
Mark Lacey
c150d656bc IUO: Update code completion output for constructor result types.
Update the code that prints types for constructor results to take
into account IUO types being removed from the type system.

NFC on master. Results in better fidelity with what we have today when
IUOs are removed from the type system in a future commit.
2018-01-30 15:06:34 -08:00
Mark Lacey
5518bae548 Update code completion printing for removal of IUOs from the type system.
This doesn't address any issues in loss of functionality when trying
to complete IUO-typed things, just the various printing issues.
2018-01-23 13:36:04 -08:00
Argyrios Kyrtzidis
f0c0405353 Merge pull request #13916 from akyrtzi/fix-clang-headers-order
[ClangImporter] Make sure that headers from the bridging header are considered 'isBeforeInTranslationUnit' compared to headers imported from swift code
2018-01-12 22:38:28 -08:00
Argyrios Kyrtzidis
18dfb2810a [swift-ide-test] Provide option '-code-completion-comments' for swift-ide-test to print documentation comments for the completion results 2018-01-12 16:09:03 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Ben Langmuir
e44eb34cd6 [code-complete] Don't suggest trailing closure for autoclosure
rdar://34921171
2018-01-03 13:33:02 -08:00
David Zarzycki
62795501d9 [AST] NFC: De-boilerplate "has ParenType sugar" 2017-12-29 11:37:20 -05:00
Ben Langmuir
cacb0bb0aa Merge pull request #13517 from benlangmuir/cc-autoclosure
[code-complete] infix operator completion in the presence of autoclosure
2017-12-18 17:07:18 -08:00
Ben Langmuir
3d7e94caaf [code-complete] infix operator completion in the presence of autoclosure
As soon as you had one &&/|| in your chain of expressions we would lose
infix completions for Bool because we got confused by the autoclosure,
so strip it off.

rdar://32016622
2017-12-18 16:11:33 -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
Doug Gregor
cd3c63cbfd [AST] Stop including GenericSignature.h in other headers.
Except GenericEnvironment.h, because you can't meaningfully use a
GenericEnvironment without its signature. Lots less depends on
GenericSignature.h now. NFC
2017-10-12 14:23:46 -07:00
Doug Gregor
1f1b75a56d [AST] Eliminate ModuleDecl parameters from GenericSignature. 2017-10-10 10:01:39 -07:00
Ben Langmuir
7685f7f31e [code-complete] Update literal protocol to show "" for Character
... and UnicodeScalar, which is technically more correct than only
showing it for String.  This also happens to workaround a bug where we
won't show "" for string.contains.

rdar://problem/34746368
2017-10-05 09:52:31 -07:00
Slava Pestov
8ffa62a370 IDE: Simplify some logic 2017-09-20 00:07:05 -07:00
Slava Pestov
ddd0666e94 IDE: Fix mismatched ErrorType check
In one place we were calling hasError() and in another directly checking
for ErrorType; if we had a type containing an ErrorType as a structural
component, we would hit an assertion.
2017-09-19 23:08:37 -07:00