Commit Graph

1207 Commits

Author SHA1 Message Date
Rintaro Ishizaki
e8cc8b55d8 [Parse] Fix #sourceLocation parsing in Decl position (#10444)
Fixes: https://bugs.swift.org/browse/SR-5242
`#sourceLocation` directive at end of declaration list postion was
rejected.
2017-06-22 12:35:43 +09:00
Huon Wilson
61606a6616 [Parse] Provide better diagnostics for func 1() {}.
It is apparently a common mistake for beginners to start the names of functions
etc. with numbers, and before this patch the diagnostic wasn't specific about
the problem. It seems likely that most instances of `func 1(...` will be
mistakes in this vein, so this patch specifically diagnoses that case, and also
parses the number as the identifier to avoid follow on errors about top-level
closures (from the {}) and other invalid syntax.

Fixes rdar://problem/32316666 .
2017-06-20 16:49:50 -07:00
Jordan Rose
77de3dc1f2 [AST] Bring 'mutating' and 'inout self' in sync. (#10375)
- A mutating method or accessor always has 'inout self'.
- A nonmutating method or accessor never has 'inout self'.
- Only instance members can be mutating.
- Addressors are still addressors even when on static members.

Came up after reviewing another patch that confused the two as
possibly distinct concepts.
2017-06-19 16:16:47 -07:00
Slava Pestov
732b215b88 Merge pull request #9413 from rintaro/ast-eliminate-ifconfigstmt
[AST] Eliminate IfConfigStmt
2017-06-16 15:39:47 -07:00
Jordan Rose
5c1967397b Update and re-enable the diagnostics for unstable runtime names.
This time, the warnings only fire when the class in question directly
conforms to NSCoding. This avoids warning on cases where the user has
subclassed something like, oh, UIViewController, and has no intention
of writing it to a persistent file.

This also removes the warning for generic classes that conform to
NSCoding, for simplicity's sake. That means
'@NSKeyedArchiverEncodeNonGenericSubclassesOnly' is also being
removed.

Actually archiving a class with an unstable mangled name is still
considered problematic, but the compiler shouldn't emit diagnostics
unless it can be sure they are relevant.

rdar://problem/32314195
2017-06-05 17:32:26 -07:00
Jordan Rose
f0aca936c7 Allow '@objc(RuntimeName)' on classes with generic ancestry.
This is accomplished by recognizing this specific situation and
replacing the 'objc' attribute with a hidden '_objcRuntimeName'
attribute. This /only/ applies to classes that are themselves
non-generic (including any enclosing generic context) but that have
generic ancestry, and thus cannot be exposed directly to Objective-C.

This commit also eliminates '@NSKeyedArchiverClassName'. It was
decided that the distinction between '@NSKeyedArchiverClassName' and
'@objc' was too subtle to be worth explaining to developers, and that
any case where you'd use '@NSKeyedArchiverClassName' was already a
place where the ObjC name wasn't visible at compile time.

This commit does not update diagnostics to reflect this change; we're
going to change them anyway.

rdar://problem/32414557
2017-06-05 17:32:25 -07:00
Alex Hoppen
de5000f9a6 [Parser] Preparations for removal of getName on ValueDecl
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 19:13:24 -07:00
Rintaro Ishizaki
c8d717e5f4 [Parse] Cleanup #if directive parsing
Now that, IfConfigDecl holds ASTNode regardless statements position or
declarations postion. We can construct it in single method.
2017-05-16 20:52:46 +09:00
Rintaro Ishizaki
6fa84150c5 [AST] Eliminate IfConfigStmt
Resolves: https://bugs.swift.org/browse/SR-4426

* Make IfConfigDecl be able to hold ASTNodes
* Parse #if as IfConfigDecl
* Stop enclosing toplevel #if into TopLevelCodeDecl.
* Eliminate IfConfigStmt
2017-05-16 12:19:54 +09:00
Rintaro Ishizaki
f1b0285bbc [Parse] Don't Hoist IfConfig{Decl,Stmt} out of IfConfig{Decl,Stmt} 2017-05-16 12:09:56 +09:00
Doug Gregor
7955aa13e6 Rename @NSKeyedArchive* attributes.
@NSKeyedArchiveLegacy -> @NSKeyedArchiverClassName
@NSKeyedArchiveSubclassesOnly -> @NSKeyedArchiverEncodeNonGenericSubclassesOnly

Fixes rdar://problem/32178796.
2017-05-15 11:02:31 -07:00
Huon Wilson
aadb959143 [Parse] Delete incorrect comment. NFC. 2017-05-11 17:01:55 +10:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Doug Gregor
aaf7933a6d Add the @NSKeyedArchiveLegacy attribute.
This attribute allows one to provide the "legacy" name of a class for
the purposes of archival (via NSCoding). At the moment, it is only
useful for suppressing the warnings/errors about classes with unstable
archiving names.
2017-05-02 22:38:32 -07:00
practicalswift
a596961187 [gardening] Make parameter name comments match actual parameter names 2017-04-20 13:47:10 +02:00
Graydon Hoare
3d5c995615 Parse @_implements(Proto, DeclName) 2017-04-18 11:12:54 -07:00
Doug Gregor
50799dc084 [AST] Track the location of the 'class' keyword for class-bounded protocols. 2017-03-21 07:36:29 -07:00
Ben Langmuir
5434afc67b [codecompletion] Fix completion after 'let' inside a nominal type
Previously, we ignoring 'let', so you would get ridiculous completions:
  let var foo: Int
  override let func bar() {}

Now, will complete protocol requirements after 'let' the same way we do
for 'var'.  For instance property overrides, we only show them if the
'override' keyword is specified.  You can't actually override using a
'let', but if the keyword is present then the intention is clear and we
can let the user fix it afterwards when the compiler diagnoses it.

rdar://problem/31091172
2017-03-17 11:33:03 -07:00
Huon Wilson
ca3a398b4a Merge pull request #8021 from huonw/protocol-where-clause
Parse/typecheck/print where clauses on protocols
2017-03-15 11:00:46 -07:00
David Hart
6de44b0fb1 [SR-3936] Fix it for missing property type
Solve SR-3936 by providing a fix-it for the “Computed property must have an explicit type” diagnostic that insert a type placeholder.
2017-03-14 22:47:02 +01:00
Huon Wilson
54f247693c [AST]/[Parse] parse where clauses on protocol declarations. 2017-03-09 16:08:16 -08:00
swift-ci
af53cb9778 Merge pull request #7733 from rintaro/parse-ifconfig-refactoring 2017-02-28 19:10:59 -08:00
Huon Wilson
8423018057 [Parse] Parse trailing where clauses on associated types. 2017-02-24 19:21:32 -08:00
Slava Pestov
928a74c47e Parse: Support for generic subscripts 2017-02-23 21:14:02 -08:00
Slava Pestov
fdb0a18647 AST: Add a GenericParamList::clone() method
This will be immediately needed for generic subscripts, and also
for fixing the remaining cases where initializer inheritance
doesn't work.
2017-02-23 20:57:15 -08:00
Rintaro Ishizaki
58c079e306 [Parse] Split out IfConfig related functions into ParseIfConfig.cpp 2017-02-24 11:07:27 +09:00
Rintaro Ishizaki
3a2f8c9a40 [Parse] Promote parseDeclItem() to Parser method 2017-02-24 01:37:48 +09:00
Rintaro Ishizaki
78b92a56c7 [Parse] Only one conditional compilation clause can be active (#7627) 2017-02-21 02:13:11 +09:00
Slava Pestov
880803aaba AST: Initial plumbing for generic subscripts 2017-02-19 21:34:26 -08:00
David Farler
431b7ff2af [Syntax] Add Equal '=' token location to TypeAliasDecl
Needed for full-fidelity structured editing.
2017-02-17 12:57:04 -08:00
Rintaro Ishizaki
3b42894f13 [Parse] Fix parsing three-version-components in #if
* Narrow allowance of 3+ components numeric literal to condition part of the
  directive.
* Allow 3+ components in '#if' directive in decl list position as well.
2017-02-16 11:35:51 +09:00
Rintaro Ishizaki
cfe742d1eb [Parse] Minor improvements in conditional compilation block parsing
* Don't emit duplicated 'expected #else or #endif at end of conditional
  compilation block' error.

    class Foo {
      #if true
        func foo() {}
    [EOF]

* Improve error message when seeing '}' in config block.

    class Foo {
    #if true
        func foo();
    } // error: unexpected '}' in conditional compilation block
    #else
    #endif
2017-02-16 11:35:51 +09:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Jacob Bandes-Storch
e1fd8aa6c7 [Parse] Fix crash in conditional compilation parsing (#7331) 2017-02-08 23:10:26 -08:00
Doug Gregor
d83f311cc1 [Parser] Throw away generic parameters we parse just for QoI.
We parse generic parameters on an associated type declaration just so
that we have provide a customized diagnostic. That's fine, but do so
in a new scope so that the generic parameters aren't visible to name
lookup.
2017-02-07 15:22:50 -08: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
Slava Pestov
dca292c652 Serialization: Don't serialize contextual enum argument type
Storing this separately is unnecessary since we already
serialize the enum element's interface type. Also, this
eliminates one of the few remaining cases where we serialize
archetypes during AST serialization.
2017-01-30 00:08:53 -08:00
Rintaro Ishizaki
9b4f549943 [Parse] Improve diagnostics for consecutive identifiers 2017-01-26 15:37:19 +09:00
Slava Pestov
a67f4bdff4 Merge pull request #6948 from matthewcarroll/SR-3599-Better-Recovery-For-Decl-Names
[DiagnosticsQoI] SR-3599: Better recovery for decls with consecutive identifiers
2017-01-23 17:37:07 -08: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
Rintaro Ishizaki
dd46acd15a [Parse] Get rid of InternalHandler in parseDecl(). We don't need this anymore. 2017-01-23 15:16:02 +09:00
Rintaro Ishizaki
6305529fe5 [Parse] Add back TrailingSemiLoc to Expr, Stmt, and Decl 2017-01-23 13:18:11 +09:00
Rintaro Ishizaki
0705506d91 [Parse] Make parseDecl() return ParserResult instead of ParserStatus 2017-01-23 13:18:11 +09:00
Rintaro Ishizaki
2192ca13b5 [Parse] Make parseDeclSubscript return ParserResult for SubscriptDecl 2017-01-23 13:18:11 +09:00
Rintaro Ishizaki
5537727046 [Parse] Make parseDeclEnumCase() return ParserResult for EnumCaseDecl 2017-01-23 13:18:11 +09:00
Rintaro Ishizaki
3705e2e4f2 [Parse] Make parseDeclVar() always return the ParserResult for PatternBindingDecl 2017-01-23 13:18:11 +09: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
93a7a9f80d [DiagnosticsQoI] SR-3599: Better recovery for decls with consecutive identifiers
Add diagnostics to fix decls with consecutive identifiers. This applies to
types, properties, variables, and enum cases. The diagnostic adds a camel-cased option if it is different than the first option.

https://bugs.swift.org/browse/SR-3599
2017-01-19 23:44:33 -05:00
Graydon Hoare
d94b76f396 Suggest narrowing an exising availability context, when feasible. 2017-01-19 16:29:16 -08:00
Roman Levenstein
ed6c0aa34b Parsing of @_specialize
The new `@_specialize` attribute has a syntax like this:

```swift
@_specialize(exported: true, kind: full, where K == Int, V == Int)
@_specialize(exported: false, kind: partial, where K: _Trivial64)
func dictFunction<K, V>(dict: Dictionary<K, V>) {
}
```

If `exported` is set, the corresponding specialization would have a public visibility and can be used by clients.
If `exported` is omitted, it's value is assumed to be `false`.

If `kind` is `full` it means a full specialization.
If `kind` is `partial` it means a partial specialization.
If `kind` is omitted, its value is assumed to be `full`.
2017-01-18 16:42:10 -08:00