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.
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.
`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) {}
^
_:
* [Parse] Remove unused GreaterThanIsOperatorRAII. NFC
Last usage was removed in 68af974227.
* [Parse] Remove unused ArgumentIsParameter flag. NFC
Last usage was removed in 4e4173f2e6
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.
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.
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
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.
- 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
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
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.
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.
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.
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.
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.