Commit Graph

531 Commits

Author SHA1 Message Date
Doug Gregor
dccf3155f1 SE-0022: Implement parsing, AST, and semantic analysis for #selector. 2016-01-26 21:12:04 -08:00
Doug Gregor
8336419844 Include completion source location information compound DeclNames.
When one spells a compound declaration name in the source (e.g.,
insertSubview(_:aboveSubview:), keep track of the locations of the
base name, parentheses, and argument labels.
2016-01-25 14:13:13 -08:00
Doug Gregor
53ed3416a5 [Parser] unqualified-identifier --> unqualified-decl-name. NFC 2016-01-21 15:06:09 -08:00
practicalswift
c764d90dfe [gardening] Fix recently introduced typos 2016-01-21 10:58:06 +01:00
Doug Gregor
fd3f03f3be Remove UnresolvedConstructorExpr.
UnresolvedConstructorExpr is not providing any value here; it's
essentially just UnresolvedDotExpr where the name refers to an
initializer, so use that instead. NFC
2016-01-20 17:09:02 -08:00
Doug Gregor
c9c1d1390c [SE-0021] Allow naming of specific initializers via "self.init(foo:bar:)". 2016-01-20 17:09:02 -08:00
Doug Gregor
ecfde0e71c Start parsing names with argument labels.
Basic implementatation of SE-0021, naming functions with argument
labels. Handle parsing of compound function names in various
unqualified-identifier productions, updating the AST representation of
various expressions from Identifiers to DeclNames. The result doesn't
capture all of the source locations we want; more on that later.

As part of this, remove the parsing code for the "selector-style"
method names, since we now have a replacement. The feature was never
publicized and doesn't make sense in Swift, so zap it outright.
2016-01-20 17:09:01 -08:00
Chris Lattner
5a4464fbca Fix <rdar://19935319> QoI: poor diagnostic initializing a variable with a non-class func
It is a common point of confusion that property initializers cannot access self, so
produce a tailored diagnostic for it.

Also, when building implicit TypeExprs for the self type, properly mark them implicit.
2016-01-18 22:37:22 -08:00
Chris Lattner
d69a1a00d7 Fix <rdar://problem/21080671> QoI: try/catch (instead of do/catch) creates silly diagnostics
People will keep typing try/catch either due to muscle memory from other languages or
when they are first learning swift.  We now produce a nice error message + fixit of:

t.swift:14:3: error: the 'do' keyword is used to specify a 'catch' region
  try {
  ^~~
  do

instead of spewing out:

t.swift:15:4: error: consecutive statements on a line must be separated by ';'
  } catch { }
   ^
   ;
t.swift:15:5: error: expected expression
  } catch { }
    ^
t.swift:15:11: error: braced block of statements is an unused closure
  } catch { }
          ^
t.swift:14:7: error: expression resolves to an unused function
  try {
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t.swift:15:11: error: expression resolves to an unused function
  } catch { }
          ^~~
t.swift:14:3: warning: no calls to throwing functions occur within 'try' expression
  try {
  ^
2016-01-17 15:14:35 -08:00
Chris Lattner
8d81349fe1 fix rdar://24029542 "Postfix '.' is reserved" error message" isn't helpful
This adds some heuristics so we can emit a fixit to remove extraneous
whitespace after a . and diagnose the case where a member just hasn't
been written yet better.  This also improves handling of tok::unknown
throughout the parser a bit.

This is a re-commit of ff4ea54 with an update for a SourceKit test.
2016-01-11 15:11:20 -08:00
Erik Eckstein
acc243a002 Revert "fix rdar://24029542 "Postfix '.' is reserved" error message" isn't helpful"
It's probably the cause for the fail of SourceKit/SyntaxMapData/syntaxmap-edit-del.swift

This reverts commit ff4ea54614.
2016-01-11 10:43:39 -08:00
Chris Lattner
ff4ea54614 fix rdar://24029542 "Postfix '.' is reserved" error message" isn't helpful
This adds some heuristics so we can emit a fixit to remove extraneous
whitespace after a . and diagnose the case where a member just hasn't
been written yet better.  This also improves handling of tok::unknown
throughout the parser a bit.
2016-01-10 15:28:03 -08:00
Chris Lattner
2f4bec9e8c subsume the "startsWithGreater" logic into skipUntilGreaterInTypeList, and make sure skipUntilGreaterInTypeList return a valid location even in the case of parse errors. This ensures that we form a valid source range. Also, improve parseExprIdentifier() to handle the case when skipUntilGreaterInTypeList returns an empty archetype argument list. This fixes a couple of compiler crashers. 2016-01-09 20:36:05 -08:00
Chris Lattner
6afe77d597 Eliminate the Parameter type completely - now ParameterList is just
an overblown array of ParamDecl*'s that also keeps track of parenlocs
and has helper methods.
2016-01-03 14:45:38 -08:00
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -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
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
fa0b339a21 Fix typos. 2015-12-26 17:51:59 +01:00
Doug Gregor
c8dd8d0661 Implement SE-0001: Allow (most) keywords as argument labels.
Allow all keywords except for parameter introducers (var/let/inout) to
be argument labels when declaring or calling a
function/initializer/subscript, e.g., this

  func touchesMatching(phase: NSTouchPhase, `in` view: NSView?) -> Set<NSTouch>

can now be expressed as

  func touchesMatching(phase: NSTouchPhase, in view: NSView?) -> Set<NSTouch>

and the call goes from

  event.touchesMatching(phase, `in`: view)

to

  event.touchesMatching(phase, in: view)

Fixes [SR-344](https://bugs.swift.org/browse/SR-344) /
rdar://problem/22415674.
2015-12-22 16:18:28 -08:00
ken0nek
fcd8fcee91 Convert [Cc]an not -> [Cc]annot 2015-12-23 00:55:48 +09:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
practicalswift
ee0c2992d5 Fix typo: cosure → closure 2015-12-14 00:11:31 +01:00
Xi Ge
2f670a8134 [CodeCompletion] Fix an assertion violation. rdar://23306548
When creating a SequenceExpr, we should always have an odd number of
elements.
2015-12-09 12:31:07 -08:00
Dmitri Hrybenko
2e51d23875 Un-ifdef object literals
Swift SVN r32880
2015-10-25 07:50:53 +00:00
Ben Langmuir
dc910fe53b [CodeCompletion] Handle sequence expression where the LHS type-checks
Now we can handle simple cases like
  1 + 1 == 2 <here>

and correctly suggest both + on the 2 and || on the boolean. When the
LHS doesn't type-check we fallback to using only the operand immediately
to the left.

Swift SVN r32489
2015-10-07 07:30:11 +00:00
Ben Langmuir
f969a9941b [CodeCompletion] Handle simple cases of space in front of postfix completions
This is pretty crude, but handles the common cases of there being 0 or 1
space between the LHS and an operator completion.

Swift SVN r32472
2015-10-06 23:35:39 +00:00
Xi Ge
2d0c1a0002 [CodeComplete] Add type relation descriptors to the member completions of assignment expressions. rdar://22706743
Swift SVN r31967
2015-09-15 19:53:43 +00:00
Xi Ge
1cb84686d4 [CodeComplete] Preserve call expr when code completion token appears in the first arg.
Swift SVN r31909
2015-09-12 00:28:28 +00:00
Xi Ge
ec4e469062 [CodeComplete] Introduce code completion expr to better preserve the context of the code completion token in ASTs.
Swift SVN r31908
2015-09-11 22:59:12 +00:00
Chris Lattner
c8990c5f66 Enhance ArrayExpr to keep track of the locations of its commas, NFC.
Swift SVN r31695
2015-09-04 22:16:23 +00:00
Xi Ge
ef3b45871b [CodeComplete] Complete arguments of call expressions.
When users invoke code completion at an argument position, we suggest argument names,
if required however not specified, or a list of argument values. These values are annotated
with their type relation to the expected argument types, so that
Xcode can prioritize those values that apply over those that do not.
This also fixes: rdar://21727063

Swift SVN r31505
2015-08-26 22:01:25 +00:00
Xi Ge
9ed7a57865 [Parser] When parsing error occurs on arguments, we still try to preserve the call expression.
This allows tools, like code completion or jumping to definition, to be able to resolve
function names even though the argument is wrong.

Swift SVN r31387
2015-08-21 19:41:11 +00:00
Xi Ge
c33e3efe59 [CodeComplete] Complete the right hand side of assignment expressions.
When users complete the right-hand side of an assignment expression, we only
show the results whose types are convertible to those of the left-hand side.

Swift SVN r31357
2015-08-20 01:35:30 +00:00
Xi Ge
40a9d61103 [CodeComplete] when completing unresolved members, we also perform name lookups for enum elements, var decls and nominal types in addition to functions.
fixes: rdar://22282057, rdar://22282116, rdar://22282224, and rdar://22282278

Swift SVN r31274
2015-08-17 21:01:54 +00:00
Xi Ge
a450a08723 [CodeCompletion] Collect the identifiers appearing before unresolved members.
We can use these identifiers to perform manual look up.

Swift SVN r31250
2015-08-14 21:16:41 +00:00
Xi Ge
0bab23961a [CodeComplete] Refine the code completion results for unresolved members by using constraint solver.
Before this commit, for unresolved members, code completion suggests all visible enum elements
 and option set types. To refine the results, this commit uses constraint solver to infer
the type of unresolved members by analyzing parental expressions. If the solver has solutions,
we complete the unresolved member, otherwise abort.
rdar://16659653

Swift SVN r31195
2015-08-13 00:19:58 +00:00
Xi Ge
0df10311a0 [CodeCompletion] Add the initial support for unresolved members.
This commit completes an unresolved member with all visible enum elements.
We need future work to reduce the list to those that are guaranteed to be
resolved under the current context.

Swift SVN r31063
2015-08-06 23:15:14 +00:00
Jordan Rose
2801d47e59 Add Parse and Sema support for 'try?'.
rdar://problem/21692467

Swift SVN r31030
2015-08-05 22:17:25 +00:00
Chris Lattner
748845aa4d Now that we have contextual type information more generally available, start
using it to improve closure diagnostics by inferring the types of otherwise
untyped closure paramdecls from this context information.  This 
resolves:

<rdar://problem/20371273> Type errors inside anonymous functions don't provide enough information
producing 
  error: binary operator '==' cannot be applied to operands of type 'Int' and 'UInt'
  note: overloads for '==' exist with these partially matching parameter lists: (UInt, UInt), (Int, Int)

and:
<rdar://problem/20978044> QoI: Poor diagnostic when using an incorrect tuple element in a closure
producing:
error: value of tuple type '(Int, Int)' has no member '2'

and probably a lot more.  We're still limited from getting things like "foo.map {...}" because 
we're not doing type subsitutions from the base into the protocol extension member.



Swift SVN r30971
2015-08-04 00:55:06 +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
66683f94f9 Eliminate the "IsReturnExpr" bit from the AST - it was a poorly maintained
version of the new CTP_ReturnStmt conversion, used to generate return-specific 
diagnostics.  Now that we have a general solution, we can just use that.

This improves diagnostics in returns for accessors, since they were apparently
not getting the bit set.


Swift SVN r30665
2015-07-26 22:05:40 +00:00
Chris Lattner
0001dc27bb remove support for the experiemental "character literals" feature.
Swift SVN r30509
2015-07-22 22:35:19 +00:00
Xi Ge
c783def2f5 [CodeCompletion] Add code completion for platform names inside #available() condition.
The code for generating the code completion string reuses that of the @available attribute.
rdar://21467109

Swift SVN r30346
2015-07-18 00:10:37 +00:00
Joe Groff
9e0b290f81 Parser: Always parse '.foo' as expr-postfix when possible.
When a line begins with '.', it's almost always due to a method chain, not an attempt to start an expression with a contextual member lookup. This is a more principled grammar rule than the long tail of hacks we've been putting up to try to accommodate "builder pattern" usages. Fixes rdar://problem/20238557.

Swift SVN r29606
2015-06-24 14:39:34 +00:00
Chris Lattner
80743ca9ce fix <rdar://problem/21387308> Fuzzing SourceKit: Parser::parseTopLevel(...) crashes in Parser::parseStmtForEach(...): Assertion failed: (InVarOrLetPattern == IVOLP_NotInVarOrLet && "for-each loops cannot exist inside other patterns")
Swift SVN r29506
2015-06-19 04:42:28 +00:00
Joe Groff
bebfa969bd Sema: Allow 'x.init' references on metatype expressions.
If 'x.init' appears as a member reference other than 'self.init' or 'super.init' within an initializer, treat it as a regular static member lookup for 'init' members. This allows a more explicit syntax for dynamic initializations; 'self.someMetatype()' looks too much like it's invoking a method. It also allows for partial applications of initializers using 'someMetatype.init' (though this needs some SILGen fixes, coming up next). While we're in the neighborhood, do some other correctness and QoI fixes:

- Only lookup initializers as members of metatypes, not instances, and add a fixit (instead of crashing) to insert '.dynamicType' if the initializer is found on an instance.
- Make it so that constructing a class-constrained archetype type correctly requires a 'required' or protocol initializer.
- Warn on unused initializer results. This seems to me like just the right thing to do, but is also a small guard against the fact that 'self.init' is now valid in a static method, but produces a newly-constructed value instead of delegating initialization (and evaluating to void).

Swift SVN r29344
2015-06-08 04:11:28 +00:00
Joe Groff
1479a56ab3 Sema: Move semantic constraints on super/self.init out of the parser.
Instead of forcing full application of '{super,self}.init' in the parser, and installing the RebindSelf semantic expr node early, make these constraints to Sema-time checks, and parse '<expr>.init' as a regular postfix production. This is a better separation of concerns, and also opens the door to supporting 'metatype.init()' in more general expression contexts (though that part still needs some follow-up sema work).

Swift SVN r29343
2015-06-08 04:11:16 +00:00
Chris Lattner
258f91f60b revert: r28801 - improve the source location information for { and } in a ClosureExpr.
Instead, provide the location of the { in a closure expr to the argument formation as 
part of the datastructure already used to manage implicit closure arguments in the parser.


Swift SVN r28818
2015-05-20 03:19:56 +00:00
Chris Lattner
db53a225ea fix <rdar://problem/19756953> Swift error: cannot capture '$0' before it is declared
This sets the location of the implicit closure decls (like $0) to being the location
of the { in a ClosureExpr, instead of the location of the first use.  The capture tracker
uses source location information of the decl and the DeclRefExpr to determine if the
referenced value was captured too early, which is what is causing this incorrect error.



Swift SVN r28802
2015-05-20 00:11:22 +00:00
Chris Lattner
66916683a2 improve the source location information for { and } in a ClosureExpr, by
actually tracking it. NFC.


Swift SVN r28801
2015-05-20 00:10:04 +00:00