Commit Graph

483 Commits

Author SHA1 Message Date
Rintaro Ishizaki
49d134f1a9 [Parse] Stop lying about QuestionLoc of implicit OptionalTypeRepr (#7384)
In conditional statement let/var patterns.
Set invalid location instead.
2017-02-11 13:39:51 +09:00
Slava Pestov
d880053dd5 Merge pull request #7050 from rintaro/parse-diag-consecutiveids
[Parse] Improve diagnostics for consecutive identifiers
2017-01-31 21:19:19 -08:00
Doug Gregor
400684e20a Merge pull request #6823 from matthewcarroll/SR-2475-Warn-when-an-unlabeled-parameter-follows-a-variadic-parameter
[QoI] SR-2475: Warn when an unlabeled parameter follows a variadic parameter
2017-01-30 10:15:05 -08:00
Slava Pestov
d3966d2567 Parse: Fix recursive diagnostic corner-case with invalid UTF8 in source file 2017-01-28 18:35:25 -08:00
Rintaro Ishizaki
9b4f549943 [Parse] Improve diagnostics for consecutive identifiers 2017-01-26 15:37:19 +09:00
Jordan Rose
dec7f9fe7e Merge pull request #6863 from matthewcarroll/SR-3600-Better-recovery-for-naming-an-initializer-deinitializer-or-subscript
[DiagnosticsQoI] SR-3600: Better recovery for trying to name an initializer, deinitializer, or subscript
2017-01-23 16:30:50 -08:00
Matthew Carroll
f8f147ecf9 [DiagnosticsQoI] SR-3600: Better recovery for trying to name an initializer, deinitializer, or subscript
- Restrict this diagnostic to identifiers that are followed by a left paren.
2017-01-21 11:32:09 -05:00
Matthew Carroll
7882ddcf40 [DiagnosticsQoI] SR-3600: Better recovery for trying to name an initializer, deinitializer, or subscript
Add a diagnostic to remove the name of an initializer, deinitializer, or subscript. The identifier token is consumed and skipped to prevent the parser from emitting additional error messages.

Add tests to verify that the name is removed from initializers, deinitializers, and subscripts declared with a name.
2017-01-17 17:21:56 -05:00
Rintaro Ishizaki
c92dbe5319 [Parse] Remove declaration list specific logic from parseList() 2017-01-17 17:19:36 +09:00
Matthew Carroll
33083f0351 [QoI] SR-2475: Warn when an unlabeled parameter follows a variadic parameter
Add a diagnostic that warns when an unlabeled parameter follows a variadic parameter.
https://bugs.swift.org/browse/SR-2475
2017-01-15 16:34:29 -05:00
Slava Pestov
5eb16e6b34 Include-what-you-use: Initializer.h should not be pulled in from AST.h 2017-01-09 16:46:31 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Robert Widmann
96f2a04f55 Merge pull request #6490 from modocache/ast
[SR-2757][Sema] Mark VarDecl in capture lists
2017-01-05 21:36:16 -07:00
Robert Widmann
e36b52c25d Resolve some compiler crashers
Crashers fixed are minor logic errors:

Patterns: Crash occurred when requesting the range of a created
Pattern.  Validity of the range should be checked before returning it
to keep the entire range valid or invalid but never both.

ParseExpr/ParsePattern: The same fixes as the ones provided in #6319

CSDiag: The generic visitor needn’t look through TypeVarTypes either.
2017-01-03 18:53:06 -07:00
Brian Gesiak
4108e1d9af [Sema] Mark VarDecl in capture lists
Fixes SR-2757.

Variables in capture lists are treated as 'let' constants, which can
result in misleading, incorrect diagnostics. Mark them as such in order
to produce better diagnostics, by adding an extra parameter to the
VarDecl initializer.

Alternatively, these variables could be marked as implicit, but that
results in other diagnostic problems: capture list variables that are
never used produce warnings, but these warnings aren't normally emitted for
implicit variables. Other assertions in the compiler also misfire when
these variables are treated as implicit.

Another alternative would be to walk up the AST and determine whether
the `VarDecl`, but there doesn't appear to be a way to do so.
2017-01-01 12:41:06 -05:00
Robert Widmann
443bc682f6 Actually improve recovery when parsing bogus expressions
The crashes fixed appeared at first to be related to IfConfigStmt
parsing, but are in reality symptoms of being too lax in what we accept
when parsing of sub-expressions fail.

Optional type annotation parsing used to propagate failures before it
was patched to ‘recover’ with an AnyPattern.  Instead, we’ll just hit
the error path for parsing in the main expressions because what is here
now isn’t a reasonable thing to return.

#selector parsing assumed that the current token it was at after
consuming up to a right-brace wasn’t bogus.  Instead, if we’ve got
here, we may as well just return a loc we know is valid: PreviousLoc.
2016-12-15 19:08:26 -05:00
Hugh Bellamy
732e3c5fdc Fix warnings building swift/Parse on Windows using MSVC 2016-12-07 22:20:49 +00:00
Rintaro Ishizaki
9eee4adc91 [Parse] Parameter list parsing cleanup
* Removed `parseConstructorArguments()`, unified with
  `parseSingleParameterClause()`.
* Use `parseSingleParameterClause()` from `parseFunctionSignature()`, so
  that we can share the recovery code.
* Removed `isFirstParameterClause` parameter from `mapParsedParameters`,
  because it's predictable from `paramContext`.
2016-12-07 23:20:30 +09:00
Argyrios Kyrtzidis
fc678740db [code-completion] Avoid a tentantive parse when in code-completion mode and make sure CodeCompletionExpr has a token range.
The tentantive parse is used for diagnostic purposes but can cause code-completion to delay the same decl twice.
The range of CodeCompletionExpr was previously character range which invalidated invariants of the AST.

Fixes:
	validation-test/IDE/crashers_fixed/084-swift-parser-consumedecl.swift
	validation-test/IDE/crashers_fixed/104-swift-gettypeofcompletioncontextexpr.swift
2016-12-05 17:09:49 -08:00
Rintaro Ishizaki
97b89adab3 [Parse] Remove redundant 'inout' parsing from parseParameterClause 2016-11-29 23:30:59 +09:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
David Farler
f450f0ccdf Revert "Preserve whitespace and comments during lexing as Trivia"
This reverts commit d6e2b58382.
2016-11-18 13:23:31 -08:00
David Farler
44f15558d6 Revert "Refactor: Rename Parser::consumeToken, consumeLoc. Add consumeToken API."
This reverts commit 39bfc123a3.
2016-11-18 13:23:31 -08:00
David Farler
39bfc123a3 Refactor: Rename Parser::consumeToken, consumeLoc. Add consumeToken API.
These APIs return SourceLocs, and eventually the Parser should consume
tokens, which now include source trivia such as whitespace and comments,
and package them into a purely syntactic tree.  Just a tiny step. NFC.
2016-11-15 16:11:57 -08:00
David Farler
d6e2b58382 Preserve whitespace and comments during lexing as Trivia
Store leading a trailing "trivia" around a token, such as whitespace,
comments, doc comments, and escaping backticks. These are syntactically
important for preserving formatting when printing ASTs but don't
semantically affect the program.

Tokens take all trailing trivia up to, but not including, the next
newline. This is important to maintain checks that statements without
semicolon separators start on a new line, among other things.

Trivia are now data attached to the ends of tokens, not tokens
themselves.

Create a new Syntax sublibrary for upcoming immutable, persistent,
thread-safe ASTs, which will contain only the syntactic information
about source structure, as well as for generating new source code, and
structural editing. Proactively move swift::Token into there.

Since this patch is getting a bit large, a token fuzzer which checks
for round-trip equivlence with the workflow:

fuzzer => token stream => file1
  => Lexer => token stream => file 2 => diff(file1, file2)

Will arrive in a subsequent commit.

This patch does not change the grammar.
2016-11-15 16:11:57 -08:00
Huon Wilson
fa56e7928d [AST] Remove redundant GenericSignatures.
The GenericSignature is now canonically available through the
GenericEnvironment.
2016-11-11 14:57:04 -08:00
Rintaro Ishizaki
2cd25c8b5e Merge pull request #5194 from rintaro/parselist-earlybailout
[Parse] Improve error handling in parseList
2016-10-14 23:22:12 +09:00
Rintaro Ishizaki
21513b8916 [Parse] Remove unecessary parameters from parseDeclAttributeList
`InParam` was not used at all.

`StopAtTypeAttributes`
As far as I understand, this option *was* merely for improving diagnostic QoI
for declarations like:
  func foo(@typeattr Arg) {}
to fix-it to:
  func foo(_: @typeattr Arg) {}

But, this causes the very loudy diagnostics for misplaced type attributes.
For example, on:
func foo(@convention(block) x: () -> CInt) {}

test.swift:1:10: error: expected parameter name followed by ':'
test.swift:1:10: error: expected ',' separator
test.swift:1:10: error: expected ')' in parameter
test.swift:1:9: note: to match this opening '('
test.swift:1:10: error: consecutive statements on a line must be separated by ';'
test.swift:1:11: error: attribute can only be applied to types, not declarations
test.swift:1:21: error: expected declaration
test.swift:1:44: error: statement cannot begin with a closure expression
test.swift:1:44: note: explicitly discard the result of the closure by assigning to '_'
test.swift:1:44: error: braced block of statements is an unused closure
test.swift:1:6: error: expected '{' in body of function declaration
test.swift:1:44: error: expression resolves to an unused function

Now, we emit more accurate diagnostic:
test.swift:1:11: error: attribute can only be applied to types, not declarations
func foo(@convention(block) x: () -> CInt) {}
          ^

Note that This causes small regression in diagnostics for bare type parameter
like `func foo(@convention(c) () -> CInt) {}`:

Before:
test.swift:1:10: error: unnamed parameters must be written with the empty name '_'
func foo(@convention(block) () -> CInt) {}
         ^
         _:

Now:
test.swift:1:11: error: attribute can only be applied to types, not declarations
func foo(@convention(block) () -> CInt) {}
          ^
test.swift:1:29: error: unnamed parameters must be written with the empty name '_'
func foo(@convention(block) () -> CInt) {}
                            ^
                            _:
2016-10-11 02:26:13 +09:00
Rintaro Ishizaki
7085e2a36c [Parse] Return error status if we cannot parse element in parameter list 2016-10-08 16:51:01 +09:00
Rintaro Ishizaki
2cac9c52ef [QoI] Improve fixit for missing parameter clause in initializer decl (#5042)
Fix `init {}` to `init() {}` instead of `init () {}`.
2016-09-29 11:02:33 +09:00
Doug Gregor
2b57b80030 [Parser] Make parameter parsing still provide useful source locations when it fails. 2016-09-15 09:16:46 -07:00
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