Commit Graph

64 Commits

Author SHA1 Message Date
Slava Pestov
a6a96da558 AST: Source range of FuncDecl/ConstructorDecl should include the thrown type
When a function declaration has a body, its source range ends at the
closing curly brace, so it includes the `throws(E)`. However, a
protocol requirement doesn't have a body, and due to an oversight,
getSourceRange() was never updated to include the extra tokens
that appear after `throws` when the function declares a thrown
error type. As a result, unqualified lookup would fail to find a
generic parameter type, if that happened to be the thrown type.

Fixes rdar://problem/143950572.
2025-02-10 09:17:40 -05:00
Alexander Cyon
a80b8ae06f [test/IDE] Fix typos 2024-08-08 19:35:00 +02:00
Hamish Knight
470cb261ef [SyntaxModel] Correctly annotate unlabelled unary args
Previously we would only handle TupleExpr argument
list exprs. Update the logic to handle ParenExpr
argument lists too.

rdar://81154978
2021-07-27 11:38:07 +01:00
Doug Gregor
836bc57fe5 [AST Walker] Stop visiting the bodies of closures as expressions.
Single-expression closures have always been traversed differently
from multi-statement closures. The former were traversed as if the
expression was their only child, skipping the BraceStmt and implicit
return, while the later was traversed as a normal BraceStmt.
Unify on the latter treatment, so that traversal

There are a few places where we unintentionally relied on this
expression-as-child behavior. Clean those up to work with arbitrary
closures, which is an overall simplification in the logic.
2020-06-04 23:06:32 -07:00
Argyrios Kyrtzidis
73c3e1c693 [IDE/SyntaxModel] For syntactic structure, make sure to not visit the captured list variables twice
rdar://59302427
2020-02-11 15:37:22 -08:00
Nathan Hawes
aa0305ee80 [Parse][IDE] Fix document structure request output for interpolated string literals
InterpolatedStringLiteralExpr has a TapExpr, which contains a BraceStmt
containing the builder CallExprs to the builder appendInterpolation /
appendStringLiteral methods used to construct the final string. This is all
implementation detail, but the BraceStmt wasn't marked implicit and had a valid
(but incorrect) SourceRange, so the document structure request treated it as
any other BraceStmt and made a structure node for it. The invalid range ended
up tripping an assertion in the document structure walker in swift-ide-test.

This patch corrects the BraceStmts produced by interpolated strings to be
marked implicit and have the correct range, and also updates ModelASTWalker to
skip over the internal details of interpolated strings when walking them (the
CallExprs were also being emitted).
2019-09-09 09:54:17 -07:00
Nathan Hawes
87d17bfb4c [IDE] Fix ModelASTWalker's handling of type attributes
When looking for the SyntaxNode corresponding to a type attribute (like
@escaping), ModelASTWalker would look for one whose range *started* at the type
attribute's source location. It never found one, though, because the
SyntaxNode's range included the @, while the type attribute's source location
pointed to the name *after* the @.
2019-08-05 11:36:32 -07:00
Nathan Hawes
218f49052a [IDE] Fix SyntaxModel crash due to out-of-order walking of EnumElementDecls
ModelASTWalker was previously constructing SyntaxNodes for EnumElementDecls
manually when visiting their associated EnumCaseDecl so that they would appear
as children rather than siblings. It wasn't actually walking these nodes
though, so missed handling some things, e.g. closures passed as default
argument values. These were also still being visited later, and because the
first visit consumed all the associated TokenNodes, this was triggering an
assertion due to the associated TokenNodes not matching expectations.
2019-07-23 09:34:25 -07:00
John Fairhurst
f841d45185 [IDE] Fix sourcerange for assoc types with default values 2019-02-06 18:10:41 +00:00
Rintaro Ishizaki
e7700dc67f [IDE] Fix SyntaxModel to corretly walk sequence expression correctly
* Handle sequence expression at call argument position
* Set the sequence expression as the parent when walking into its sub
  expressions.
* Correctly call walkToExprPost() to the sequence expression.

rdar://problem/47603866 / https://bugs.swift.org/browse/SR-9776
2019-01-28 11:25:07 -08:00
Rintaro Ishizaki
fedc36e4fb [IDE] Don't walk to ExplicitCast expr twice in ModelASTWalker
Explict cast expressions (i.e. 'as', 'as!`, 'as?', and 'is') appear twice in
'SequenceExpr'. For instance, 'a as B' is parsed as:
  (sequence_expr
    (unresolved_declref_expr name='a')
    (coerce_expr writtenType='B')
    (coerce_expr writtenType='B'))
This patch prevents ModelASTWalker from walking into them twice.

rdar://problem/43135727
2018-08-14 08:19:48 +09:00
Alex Hoppen
4f43c8e93c [SourceKit] Make the NameLength of EnumElements take argument labels into account 2018-05-10 11:27:49 -07:00
Xi Ge
7224ef84bb Merge pull request #15595 from johnfairh/whither-where
[SourceKit] Include trailing where clause in SourceRange
2018-03-29 10:58:55 -07:00
John Fairhurst
f99321a092 [SourceKit] Include trailing where clause in SourceRange 2018-03-29 11:38:21 +01: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
Sho Ikeda
b68be20e9d [test][gardening] Prefer os(macOS) over os(OSX) 2018-03-11 10:58:58 +09:00
Marcelo Fabri
94465a38c0 [SourceKit] Add GenericTypeParam to structure (SR-5474) (#13616) 2018-01-09 17:28:52 -08:00
Marcelo Fabri
b6ecf9c6d4 [SourceKit] Introduce "source.lang.swift.expr.closure" in structure (SR-6116) (#13617) 2018-01-04 10:45:29 -08:00
Marcelo Fabri
95383df793 [SourceKit] Introduce "source.lang.swift.expr.tuple" (SR-5977) (#12089) 2017-09-27 10:08:27 -07:00
Marcelo Fabri
5c65887fd0 [SourceKit] Add function argument when optional chaining is used (SR-5717) (#11542) 2017-08-29 12:59:43 -07:00
Marcelo Fabri
8b9b49fdf3 [SourceKit] Add associatedtype to doc structure (SR-5700) 2017-08-16 23:40:36 +02:00
Marcelo Fabri
c639147f02 [SourceKit] Include function return type in function kinds structure (SR-5613) 2017-08-14 20:53:00 +02:00
Marcelo Fabri
40b054b642 [SourceKit] Add local variables to structure (SR-5057) (#11431) 2017-08-11 13:43:05 -07:00
Rintaro Ishizaki
eb6914ccfc Merge pull request #11346 from rintaro/rip-cfor
Eliminate C-style ForStmt
2017-08-08 07:49:42 -07:00
Xi Ge
6573a5fe41 SourceKit: Report the signature length for subscript declarations. SR-5626 (#11376) 2017-08-07 14:11:52 -07:00
Rintaro Ishizaki
546aeb2336 [Parse] Remove Parser support for C-style for statement. 2017-08-04 23:27:15 +09:00
Marcelo Fabri
c4dad0c321 [SourceKit] Add subscript to doc structure (SR-5035) 2017-08-01 00:00:20 +02:00
John Fairhurst
1f94eca80c [SourceKit] Add typealias to doc structure (#11143)
From https://bugs.swift.org/browse/SR-4828
2017-07-26 09:59:06 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Xi Ge
195c737b54 [libIDE] Add syntax kind of argument to fix a crash. rdar://27377118
Argument used to have the same syntax kind with that of parameter. This patch
starts to differentiate them.
2016-07-19 15:10:46 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
David Farler
3f635d04c7 Reinstante var bindings in refutable patterns, except function parameters.
This reverts commits: b96e06da44,
                      8f2fbdc93a,
                      93b6962478,
                      64024118f4,
                      a759ca9141,
                      3434f9642b,
                      9f33429891,
                      47c043e8a6.

This commit leaves 'var' on function parameters as a warning to be
merged into Swift 2.2. For Swift 3, this will be an error, to be
converted in a follow-up.
2016-01-29 15:27:08 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
David Farler
a759ca9141 Disallow 'var' bindings in case patterns
Make the following illegal:

switch thing {
  case .A(var x):
    modify(x0
}

And provide a replacement 'var' -> 'let' fix-it.

rdar://problem/23172698

Swift SVN r32883
2015-10-25 18:53:02 +00:00
Xi Ge
682e4320d8 [SyntaxModel] Adjust the end loc when converting from SourceRange to CharSourceRange. rdar://22676599
Swift SVN r32013
2015-09-16 21:58:53 +00:00
Xi Ge
a21010e8f7 [SyntaxColor] Teach syntax model walker not to walk into active regions inside #if config stmt twice. rdar://22224993
Swift SVN r31433
2015-08-24 18:28:08 +00:00
Jordan Rose
953424072e Guard "object literals" feature with SWIFT_ENABLE_OBJECT_LITERALS.
This is not a feature we're releasing at the moment, so provide a way
to turn it off.

rdar://problem/21935551

Swift SVN r30966
2015-08-04 00:16:52 +00:00
Chris Lattner
b075f810ba Reimplement error recovery in C-style for statement, where we'd turn a ClosureExpr
into the body of the for statement.  Instead of ripping the body of the closureexpr
out and putting it into the C Style for, wrap up the closureExpr into a call.  This
avoids breaking AST invariants because the ClosureExpr will be the DeclContext for
anything inside of it.

This fixes <rdar://problem/21679557> compiler crashes on "for{{"
... which was Practical Swift's shortest crasher.



Swift SVN r29916
2015-07-06 06:19:30 +00:00
Xi Ge
29cebb8ac5 [SyntaxModel] Ensure syntax-coloring does not crash when the last token is a DeclAttribute.
This may happen to rethrows, rdar://21324493

Swift SVN r29472
2015-06-17 23:35:58 +00:00
Ted Kremenek
02041a9e6f Revert "Revert "fix <rdar://problem/20883210> QoI: Following a "let" condition with boolean condition spouts nonsensical errors""
I thought this was the culprit behind the SourceKit test failure, but I was wrong.

Swift SVN r28621
2015-05-15 07:05:55 +00:00
Argyrios Kyrtzidis
7c69b077c7 [IDE] Add enum elements in the document structure.
rdar://18845613

Swift SVN r28618
2015-05-15 06:56:22 +00:00
Ted Kremenek
3ab75178de Revert "fix <rdar://problem/20883210> QoI: Following a "let" condition with boolean condition spouts nonsensical errors"
This is causing a regression with 'while ... where', and manifests in the SourceKit tests.

Swift SVN r28616
2015-05-15 06:50:10 +00:00
Chris Lattner
e6344e4ad6 fix <rdar://problem/20883210> QoI: Following a "let" condition with boolean condition spouts nonsensical errors
Swift SVN r28596
2015-05-15 01:14:20 +00:00
Greg Parker
847e321138 [test] Undo Linux XFAILs.
These failures either are intermittent or were fixed just before 
they were disabled.


Swift SVN r28548
2015-05-14 00:50:39 +00:00
Greg Parker
94958e14f3 [test] XFAIL two tests on Linux because swift-ide-test is crashing.
rdar://20946478


Swift SVN r28542
2015-05-13 23:47:41 +00:00
Maxwell Swadling
d239d4434f Added IDE support for Object Literals Expressions
Fixes rdar://problem/20839100
Object Literal Expressions now show up in the Document structure.

Swift SVN r28332
2015-05-08 23:22:09 +00:00
Chris Lattner
31c01eab73 Change the meaning of "if let x = foo()" back to Xcode 6.4 semantics. The compiler
includes a number of QoI things to help people write the correct code.  I will commit
the testcase for it as the next patch.

The bulk of this patch is moving the stdlib, testsuite and validation testsuite to
the new syntax.  I moved a few uses of "as" patterns back to as? expressions in the 
stdlib as well.



Swift SVN r27959
2015-04-30 04:38:13 +00:00
Chris Willmore
c7c7388cf2 Change do-while to repeat-while.
Change all uses of "do { ... } while <cond>" to use "repeat" instead.
Rename DoWhileStmt to RepeatWhileStmt. Add diagnostic suggesting change
of 'do' to 'repeat' if a condition is found afterwards.

<rdar://problem/20336424> rename do/while loops to repeat/while & introduce "repeat <count> {}" loops

Swift SVN r27650
2015-04-23 22:48:31 +00:00
Argyrios Kyrtzidis
7c5f1e8c1d [IDE] Make sure we don't leave structure nodes without pop'ing them.
rdar://20457518

Swift SVN r27119
2015-04-08 05:03:08 +00:00
Chris Lattner
59c22383fb Rework PatternBindingDecl to maintain a list of pattern/initexpr pairs inside of it.
Previously, a multi-pattern var/let decl like:
  var x = 4, y = 17

would produce two pattern binding decls (one for x=4 one for y=17).  This is convenient
in some ways, but is bad for source reproducibility from the ASTs (see, e.g. the improvements
in test/IDE/structure.swift and test/decl/inherit/initializer.swift).

The hardest part of this change was to get parseDeclVar to set up the AST in a way
compatible with our existing assumptions. I ended up with an approach that forms PBDs in 
more erroneous cases than before.  One downside of this is that we now produce a spurious
  "type annotation missing in pattern"
diagnostic in some cases.  I'll take care of that in a follow-on patch.





Swift SVN r26224
2015-03-17 16:14:18 +00:00