Commit Graph

302 Commits

Author SHA1 Message Date
Rintaro Ishizaki
d75c4c4cbb [gardening][Parse] Remove 2 unused flags in Parser (#4743)
* [Parse] Remove unused GreaterThanIsOperatorRAII. NFC

Last usage was removed in 68af974227.

* [Parse] Remove unused ArgumentIsParameter flag. NFC

Last usage was removed in 4e4173f2e6
2016-09-13 21:54:03 -07:00
Doug Gregor
78b007f178 Always create a DefaultArgumentInitializer for a parameter with a default argument.
As with pattern binding initializer contexts, we were trying to
optimize away these contexts, leading to an unpredictable AST.
2016-09-02 13:51:00 -07:00
Doug Gregor
85537fd66b Murder ExprHandle in cold blood. NFC
ExprHandle is a relic from a horrible time when expressions made their
way into the type system via default arguments. It's been unnecessary
for a long time, so get rid of it.
2016-09-02 10:39:19 -07:00
Rintaro Ishizaki
ba982bc01c [Diag] Make fixItReplace slightly smart
When replace something with a punctuator, we often prefer adding spaces around it.
For instance,

   func foo(): bar {}
   // fix it
   func foo() -> bar {}

In this case we want to add a space before '->', but not after that.

With this change, we can simply `fixItReplace(ColonLoc, " -> ")`.
`fixItReplace()` automatically adjust the spaces around it.
2016-08-25 13:51:55 +09:00
Jacob Bandes-Storch
73830dfff9 [QoI] diagnose initializers written as typed patterns (SR-1461) 2016-08-22 08:59:45 -07:00
Jordan Rose
294bbd8e17 [Parse] Attach 'inout' to Swift 2 unparenthesized function params. (#4241)
This syntax is no longer permitted, but we need to parse it like Swift
2 did in order to produce the fix-it that matches Swift 2 behavior.

rdar://problem/26681485
2016-08-11 16:42:06 -07:00
Slava Pestov
522f4e4572 AST: Replace recently-added IsInOut bit with simpler check, NFC
Thanks to @lattner for the suggestion.
2016-08-05 14:27:16 -07:00
Slava Pestov
9a1fa52ff2 Sema: Fix bogus 'parameters may not have the 'var' specifier' diagnostic
If an inout parameter has an invalid type, we were unable to
distinguish it from a 'var' parameter, resulting in an invalid
diagnostic.

Fix this by adding a VarDecl::isInOut() flag, instead of
introspecting the type.
2016-08-01 23:56:11 -04:00
Harlan
162648d219 Add fixit for '-> throws' to 'throws ->' (#3335) 2016-07-05 11:29:55 -07:00
David Farler
414cfe7487 Minor changes to keyword-as-identifier diagnostics
- Remove stray newline
- Adjust wording when recommending backticks for a keyword identifier
- Provide fix-it when encountering a keyword as an identifier

rdar://problem/25761380
2016-05-10 14:49:21 -07:00
David Farler
b4dbdc49c2 Provide a more specific diag when using keywords as identifiers
When declaring a function like func repeat(){}, the diagnostic is
"expected an identifier" but 'repeat' looks like a reasonable
identifier at first glance, so actually say why it isn't.

rdar://problem/25761380
2016-05-10 11:08:13 -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
Joe Groff
2afece3e7c Remove warning about explicit '_' arguments.
SE-0046 will make the '_' necessary to suppress the first keyword label. This warning interferes with writing future-proof code.
2016-03-31 17:06:22 -07:00
Manav Gabhawala
7862f104c9 [Parser] Cleans up parsing of parameter attributes. Implements SE-0053. Fixes SR-979, SR-1020 and cleans up implementation of SE-0003. Provides better fix-its and diagnostics for misplaced 'inout' and prohibits 'var' and 'let' from parameter attributes 2016-03-29 13:55:46 -04:00
Chris Lattner
79968ab7e9 simplify some code related to the inout move. 2016-02-26 11:30:47 -08:00
Daniel Duan
f48487d3fb [Parser] adjust inout declaration for type decoration
This commit implements [SE-0031](//github.com/apple/swift-evolution/blob/master/proposals/0031-adjusting-inout-declarations.md).
When `inout` appears before parameter name, the parser issues a warning and
suggests the correct alternate location for it.

`inout` prefixing the paramter type is now valid.
2016-02-26 01:33:19 -08:00
Daniel Duan
efe230774b [AST] rename some isXXX methods to getAsXXX
There's a group of methods in `DeclContext` with names that start with *is*,
such as `isClassOrClassExtensionContext()`. These names suggests a boolean
return value, while the methods actually return a type declaration. This
patch replaces the *is* prefix with *getAs* to better reflect their interface.
2016-02-11 16:23:40 -08:00
Chris Lattner
8cc0ab170a fix a potential problem that Jordan noticed by inspection, NFC on the testsuite. 2016-02-01 21:02:00 -08:00
Chris Lattner
94dd92fcb8 Fix compiler_crashers 22725 & 28236 by reworking parameter parsing error
recovery a bit.
2016-02-01 20:50:32 -08:00
Chris Lattner
3ae9de1861 remove some old code that isn't doing anything useful in the testsuite,
but regresses parser recovery with a forthcoming patch I'm working on.
2016-02-01 12:28:50 -08:00
Chris Lattner
9b503272a4 fix compiler_crashers/28232-swift-typechecker-typecheckfunctionbodyuntil.swift 2016-01-31 21:46:34 -08: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
Denis Vnukov
4f92a08987 Adding a location of the var/let/inout to ParamDecl 2016-01-27 13:43:42 -08:00
Dmitri Gribenko
d046d88821 Revert "[Parser] Fix-it for declaration attributes being applied to parameter types (SR-215)" 2016-01-25 16:55:19 -08:00
Joshua Garnham
ce69f1d260 Decl attr applied to type check now more rigorous
Checks decl options to ensure it can be applied to a parameter & handles no escape special case as it's not a type attribute unless in SIL mode
2016-01-24 20:34:08 +00:00
Chris Lattner
28b71e18b3 Fix two regressions on the validation tests. We're passing down default arg info when
parsing curried arguments in some cases, even though that makes no sense.  This will get
cleaned up when they are removed.
2016-01-23 09:20:45 -08:00
Chris Lattner
f0377bee52 Fix <rdar://problem/22753605> QoI: bad diagnostic when closure has default argument
Fix <rdar://problem/16812341> QoI: Poor error message when providing a default value for a subscript parameter

by emitting a more specific diagnostic about the cases that aren't allowed.
2016-01-22 23:25:47 -08:00
Chris Willmore
983a674e0c Make use of curried function declaration syntax an error.
<rdar://problem/23111018>
2016-01-20 21:57:38 -08:00
Chris Lattner
4db5b98535 fix SR-573 - Crash with invalid parameter declaration
This makes sure to diagnose the error of not having a type on a parameter
in the parser, which is what sema expects.
2016-01-18 09:03:58 -08:00
Chris Lattner
73ec7006ee Simplify mapParsedParameters/createParam by passing the ParsedParameter
into it, instead of passing a bunch of pieces into it.  NFC.
2016-01-18 09:03:58 -08:00
David Farler
a6f2530780 Revert "REVERTME: Temporarily make vars in refutable patterns a warning"
This reverts commit b96e06da44, making
vars in refutable patterns an error for Swift 3.

rdar://problem/23172698
2016-01-14 20:52:24 -08:00
Dmitri Gribenko
f40c2a5b7f Revert "[Parser] Fix-it for declaration attributes being applied to parameter types (SR-215)" 2016-01-12 17:57:56 -08:00
Joshua Garnham
9ced244564 Corrected check for declaration attribute 2016-01-12 21:54:35 +00:00
Joshua Garnham
6b7eb00be7 Removed reference to bug ID 2016-01-12 11:52:26 +00:00
Joshua Garnham
d231cb0321 Add check for decl attributes being applied to types in function declaration (fixes SR-215) 2016-01-12 11:49:45 +00:00
Chris Lattner
a20fa87712 Fix a bug that I noticed when doing the parameter rework, where we'd accidentally
accept closure arguments with API names (but only in a parenthesized parameter list).
While it could theoretically be interesting to support API names on closures, this
is never something we intended to support, and a lot of implementation work would be
necessary to make them correct.  Just correctly reject them even if parenthesized.
2016-01-09 21:20:13 -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
b170b700f8 move the rest of the state out of Parameter and into ParamDecl,
in prep for Parameter going away.  NFC.
2016-01-01 15:27:53 -08:00
Chris Lattner
4479b46ef0 move the TypeLoc for a parameter out of Parameter and onto ParamDecl. NFC. 2016-01-01 14:13:13 -08:00
Chris Lattner
5ce3de8dd6 remove & dial back three old bits of syntax auto-upgrading support:
1. Array type parsing for postfix array types Int[].  We now handle this
   in the parser, but remove the AST representation of this old form.  We
   also stop making vague promises about the future by saying that "fixed
   size arrays aren't supported... yet".  Removal of this fixes a compiler
   crasher too.

2. Remove the special case support for migrating @autoclosure from types
   to parameters, which was Swift 1.0/1.1 syntax.  The world has moved or
   we don't care anymore.

3. Remove upgrade support for # arguments (nee "backtick" arguments), which
   was a Swift 1.x'ism abolished in an effort to simplify method naming
   rules.

NFC on valid code.
2015-12-31 22:29:39 -08:00
Chris Lattner
cc3f173040 remove variadics, default args etc, from tuple patterns, and simplify
the Pattern::clone interface now that the complexity isn't needed.
This also removes support for serializing this state.
2015-12-31 20:12:12 -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
Chris Lattner
666a42f5c7 Remove the ability to map back from a ParamDecl to its enclosing Pattern. This
is used by precisely one thing (producing a warning in a scenario that is obsolete
because we deprecated the entire thing), so the complexity isn't worth it anymore.
2015-12-29 21:09:11 -08:00
practicalswift
22e10737e2 Fix typos 2015-12-26 01:19:40 +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
3d1a386d11 Fix typo: ambiguious → ambiguous 2015-12-13 23:56:40 +01:00
David Farler
b96e06da44 REVERTME: Temporarily make vars in refutable patterns a warning
Revert "Make function parameters and refutable patterns always
immutable"

This reverts commit 8f2fbdc93a.

Once we have finally merged master into the Swift 2.2 branch to be, we
should revert this commit to turn the errors back on for Swift 3.0.
2015-12-05 23:13:04 -08:00