Commit Graph

42 Commits

Author SHA1 Message Date
Doug Gregor
38c1de69e4 Reinstate "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit ce7b2bcf09, tweaking
a few validation tests appropriately (1 crasher fixed, two -verify
tests that needed updating).
2016-01-14 00:21:48 -08:00
Erik Eckstein
ce7b2bcf09 Revert "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit 2b2e9dc80e.

It broke some compiler crasher tests
2016-01-13 20:42:58 -08:00
gregomni
2b2e9dc80e [SR-511][Parse] Add 'associatedtype' keyword and fixit
Adds an associatedtype keyword to the parser tokens, and accepts either
typealias or associatedtype to create an AssociatedTypeDecl, warning
that the former is deprecated. The ASTPrinter now emits associatedtype
for AssociatedTypeDecls.

Separated AssociatedType from TypeAlias as two different kinds of
CodeCompletionDeclKinds. This part probably doesn’t turn out to be
absolutely necessary currently, but it is nice cleanup from formerly
specifically glomming the two together.

And then many, many changes to tests. The actual new tests for the fixits
is at the end of Generics/associated_types.swift.
2016-01-13 17:54:31 -08:00
Slava Pestov
c258f991f6 Sema: Nuke NominalTypeDecl::markInvalidGenericSignature()
This would just set the NominalTypeDecl's declared type to
ErrorType, which caused problems elsewhere.

Instead, generalize the logic used for AbstractFunctionDecl.
This correctly wires up the GenericTypeParamDecl's archetypes even
if the signature didn't validate, fixing crashes if the generic
parameters of the type are referenced.
2015-12-14 13:29:55 -08:00
Chris Lattner
ada5487153 add fixit tests to random other tests.
Swift SVN r31006
2015-08-04 20:35:36 +00:00
Chris Lattner
649e5f937d generalize the existing ? and + constraints on expected diagnostics to
a simpler and more general * constraint.  This paves the way for other improvements.



Swift SVN r30622
2015-07-25 05:23:30 +00:00
Doug Gregor
54979b70a7 Remove uses of complete-unnamed function parameters from the testsuite.
Support for "func f(Int)" is going away.

Swift SVN r29608
2015-06-24 16:01:37 +00:00
Chris Lattner
3ad108b0be Reapply r29419:
Enhance fixItRemove() to be a bit more careful about what whitespace it leaves around: if the thing it is removing has leading and trailing whitespace already, this nukes an extra space to avoid leaving double spaces or incorrectly indented results.  

This includes an extra fix for looking off the start of a buffer, which extractText doesn't and can't handle.

This fixes <rdar://problem/21045509> Fixit deletes 'let' from non-binding 'if case let' statements, but leaves an extra space




Swift SVN r29449
2015-06-17 16:31:26 +00:00
Ted Kremenek
d13549e607 Revert "enhance fixItRemove() to be a bit more careful about what whitespace it leaves around:"
This was breaking the bots.

Swift SVN r29432
2015-06-17 02:20:52 +00:00
Chris Lattner
6b3167ab36 enhance fixItRemove() to be a bit more careful about what whitespace it leaves around:
if the thing it is removing has leading and trailing whitespace already, this nukes
an extra space to avoid leaving double spaces or incorrectly indented results.  This
fixes <rdar://problem/21045509> Fixit deletes 'let' from non-binding 'if case let' statements, but leaves an extra space



Swift SVN r29419
2015-06-17 00:55:59 +00:00
Chris Lattner
5248ededee Rework the AST representation of CollectionExprs to maintain
a list of their elements, instead of abusing TupleExpr/ParenExpr
to hold them.

This is a more correct representation of what is going on in the
code and produces slightly better diagnostics in obscure cases.

However, the real reason to fix this is that the ParenExpr's that
were being formed were not being installed into the "semantic"
view of the collection expr, not getting type checked correctly,
and led to nonsensical ParenExprs.  These non-sensical ParenExprs
blocked turning on AST verification of other ones.

With this fixed, we can finally add AST verification that 
IdentityExpr's have sensible types.



Swift SVN r27850
2015-04-28 01:09:10 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Joe Pamer
1ea993c317 If the generic type parameters of a class or struct declaration are invalid or otherwise broken, we should treat the declaration as invalid, and be more careful about doing anything that could lead to the creation of bogus archetypes. (Such as implicit constructor/destructor generation, or conformance checking.)
This addresses crash suite scenario 022. (rdar://problem/18232772)

Swift SVN r22095
2014-09-18 20:10:02 +00:00
Jordan Rose
a6d9e8573b [Accessibility] Downgrade "public method in private struct" to a warning.
If someone's experimenting with access control, this will allow them to flip
between "internal" and "public" without updating all of their required
members immediately. Public members on a private type don't actually hurt
anything.

Swift SVN r20935
2014-08-02 01:04:59 +00:00
Doug Gregor
eee00ca58b Require 'required' keyword when overriding a required initializer.
Swift SVN r20489
2014-07-24 15:30:15 +00:00
Jordan Rose
89d1cb393c [Accessibility] Private extensions cannot contain public methods.
The decision on the mailing list was that just as internal types can have
either internal or private members, an extension implicitly marked 'internal'
can have either internal or private members, but no public members. This
occurs when an extension is given an explicit accessibility that is less
than the type's accessibility.

Swift SVN r20226
2014-07-20 17:26:27 +00:00
Jordan Rose
2119961b23 [Accessibility] A public extension cannot be declared for a private type.
...since you can't actually declare public /members/ for a private type.

Swift SVN r20225
2014-07-20 17:26:25 +00:00
Jordan Rose
8f520414b7 [Accessibility] A private class cannot contain public methods.
There's no meaningful way in which these methods are public, since they
can't be accessed through any value of the type

<rdar://problem/17647878>

Swift SVN r20224
2014-07-20 17:26:24 +00:00
Chris Lattner
fe95f81397 introduce a new 'DeclModifier' flag on attributes, which mark that the
attribute is a "modifier" of a decl, not an "attribute" and thus shouldn't
be spelt with an @ sign.  Teach the parser to parse "@foo" but reject it with
a nice diagnostic and a fixit if "foo" is a decl modifier.

Move 'dynamic' over to this (since it simplifies some code), and switch the
@optional and @required attributes to be declmodifiers (eliminating their @'s).



Swift SVN r19787
2014-07-10 05:49:10 +00:00
Jordan Rose
6752d856ca [Accessibility] Private members cannot override public members.
...unless they are in a private class.

Consider this scenario:

  class Base {
    func foo() -> Base { ... }
  }
  class Sub : Base {
    private override func foo() -> Sub { ... }
  }
  class Grandchild : Sub {
    override func foo() -> Base { ... }
  }

Because Grandchild can't see Sub, its override of foo() looks perfectly
reasonable...but now Sub's expectations for foo() have been broken.

Swift SVN r19769
2014-07-10 01:20:10 +00:00
Jordan Rose
0f0714f625 s/must have (internal|public) access/must be declared $1/ in diagnostic.
Thanks, Chris!

Swift SVN r19759
2014-07-09 23:01:11 +00:00
Jordan Rose
f588ed43a8 Don't use the word "accessibility" in diagnostics.
Reserve "accessibility" for the Accessibility APIs and concepts in our
frameworks. "Access" and "accessible" are okay, though.

Swift SVN r19748
2014-07-09 22:10:21 +00:00
Jordan Rose
faa0fc4e41 [Accessibility] Setter requirements must be public for public conformances.
That is, if a protocol specifies that a property or subscript is settable,
check the accessibility of the conforming type's setter.

Swift SVN r19714
2014-07-09 00:07:45 +00:00
Jordan Rose
ac90133b8c Update tests for accessibility modifiers becoming context-sensitive keywords.
Swift SVN r19673
2014-07-08 02:17:49 +00:00
Jordan Rose
faa4004b42 [Accessibility] Public types/functions cannot have private generic parameters.
Or rather, they cannot have constraints on their generic parameters that use
private types.

Swift SVN r19644
2014-07-07 22:52:29 +00:00
Jordan Rose
2836c474ec [Accessibility] Public enum cases cannot have private payloads.
...because you can't match them properly in switches.

In the future, we could consider allowing private enum cases in a
resilient public enum, which essentially forces the user to consider the
default case.

Swift SVN r19620
2014-07-07 18:39:35 +00:00
Jordan Rose
19e0ce96a0 [Accessibility] Public classes may not have private superclasses.
In theory there's nothing wrong with this, but it makes it hard to see what
operations a class supports, and there's no obvious way to go to its nearest
public superclass.

Note that we have a similar issue with protocols, since private protocols can
refine public protocols, and then public classes can conform to private
protocols---the indirect conformance won't be listed in the inheritance
clause, but it is a public conformance nonetheless.

Swift SVN r19588
2014-07-06 22:23:06 +00:00
Jordan Rose
4c438ec5d0 [Accessibility] A public enum cannot have a private raw type.
While this could be useful, a raw type implies a conformance to
RawRepresentable, and private methods cannot be used to satisfy conformances
of public types to public protocols.

Swift SVN r19587
2014-07-06 22:07:29 +00:00
Jordan Rose
56ec3c901c [Accessibility] Properly treat typealiases as distinct types.
getAnyNominal() looks through sugar, so it was matching typealiases to
nominal types before the specific check for typealiases.

Swift SVN r19586
2014-07-06 22:07:28 +00:00
Jordan Rose
0fac468f47 [Accessibility] Public protocols cannot refine private protocols.
Otherwise, how is an implementer to know all the requirements?

Swift SVN r19584
2014-07-06 20:44:31 +00:00
Jordan Rose
7d1371c6e5 -verify: Bring over Clang's "+" to signify "at least one" diagnostic to match.
This is useful for expected-note in particular (e.g. "declared here" notes).

Swift SVN r19521
2014-07-03 17:45:38 +00:00
Jordan Rose
8080ca6820 [Accessibility] Public functions/initializers may not use private types.
Also, don't diagnose accessibility violations on implicit decls. Every now
and then the compiler needs to bend the rules, such as when providing an ==
implementation for a local enum.

Swift SVN r19519
2014-07-03 17:45:36 +00:00
Jordan Rose
f0bcc5cf2d [Accessibility] Fix existing checks to work with protocol requirements as well.
Going forward, everything will be added to checkAccessibility.

Swift SVN r19494
2014-07-02 23:54:51 +00:00
Jordan Rose
43ca8fcd83 [Accessibility] Check requirements and default definitions of associated types.
We could actually allow the default definition of an associated type to have
less accessibility than the requirement, but then we'd also have to check
that that type wasn't being used where it wasn't accessible. Since we infer
associated types anyway, it's probably not worth it.

Swift SVN r19493
2014-07-02 23:54:51 +00:00
Jordan Rose
62a96d7ff4 [Accessibility] Check the index and element types of subscripts.
Swift SVN r19446
2014-07-02 01:07:30 +00:00
Jordan Rose
169238e146 [Accessibility] Check type accessibility for variables with inferred types.
We'd rather check the explicit type, because we can give a better diagnostic,
but we still need to check inferred types as well.

Swift SVN r19438
2014-07-01 23:42:06 +00:00
Jordan Rose
3412be23bf [Accessibility] Collapse two diagnostics into one, and drop the typealias name.
The diagnostic is printed at the declaration site; it's obvious which
typealias it is.

Swift SVN r19437
2014-07-01 23:42:05 +00:00
Jordan Rose
cfd7851a67 [Accessibility] When a private type is used in a public way, show its decl.
At the very least, this makes it easier to mark the private type as public
if that's the correct answer.

Swift SVN r19436
2014-07-01 23:42:01 +00:00
Jordan Rose
f746b8c6dd [Accessibility] Public variables cannot have private types.
This does not yet handle variables with inferred types, since those don't
have TypePatterns.

There is some nasty propagation of @public into the stdlib because of this
one, mainly because Foundation needs access to some of the implementation
details of Array and Dictionary. We may want to try to improve this later
(or just build Foundation with -disable-access-control if it comes to that).

Swift SVN r19432
2014-07-01 22:30:53 +00:00
Jordan Rose
f13a5af044 [Accessibility] A typealias cannot be more accessible than its underlying type.
This actually lays the groundwork for checking the TypeLocs for all sorts
of decls, but let's start with typealiases.

Swift SVN r19428
2014-07-01 20:46:30 +00:00
Jordan Rose
d545ac1623 [Accessibility] @required initializers must be as accessible as the type.
Swift SVN r19383
2014-06-30 23:38:36 +00:00
Jordan Rose
748efed913 [Accessibility] Protocol witnesses must be as accessible as the protocol.
...unless the type has less accessibility than the protocol, in which case
they must be as accessible as the type.

This restriction applies even with access control checking disabled, but
shouldn't affect any decls not already marked with access control modifiers.

Swift SVN r19382
2014-06-30 23:38:35 +00:00