Commit Graph

77 Commits

Author SHA1 Message Date
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