Commit Graph

32 Commits

Author SHA1 Message Date
Chris Lattner
4341ef35cd Move CalleeCandidateInfo to using NameLookupFlags::IgnoreAccessibility
for initializer lookup, allowing it to produce more specific diagnostics
when referring to a private initializer that the compiler can see.

In addition to improving diagnostics, this allows us to eliminate the
NoPublicInitializers failure kind.
2016-01-19 22:52:26 -08:00
Chris Lattner
8a41d14b2d Fix <rdar://problem/21429694> QoI: diagnostic for accessing private methods could be improved
When member lookup completely fails and when CSDiags is the one performing
the lookup, reissue another lookup that ignores access control.  This allows
it to find inaccessible members and diagnose them as such, instead of pretending
we have no idea what the user wants.  We now produce an error message like this:

main.swift:1:6: error: 'foo' is inaccessible due to 'private' protection level
 C().foo()
     ^
test.swift:1:35: note: 'foo' declared here
  internal class C { private func foo() {} }
                                  ^

instead of:

main.swift:1:2: error: value of type 'C' has no member 'foo'
 C().foo()
 ^~~ ~~~
2016-01-17 17:13:07 -08:00
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
Chris Lattner
ede0c50856 Revamp how value & type member constraint failures are diagnosed, eliminating the
"unavoidable failure" path, along with Failure::DoesNotHaveNonMutatingMember and
just doing some basic disambiguation in CSDiags.

This provides some benefits:
 - Allows us to plug in much more specific diagnostics for the existing "only has 
   mutating members" diagnostic, including producing notes for why the base expr
   isn't mutable (see e.g. test/Sema/immutability.swift diffs).
 - Corrects issues where we'd drop full decl name info for selector references.
 - Wordsmiths diagnostics to not complain about "values of type Foo.Type" instead 
   complaining about "type Foo"
 - Where before we would diagnose all failures with "has no member named", we now
   distinguish between when there is no member, and when you can't use it.  When you
   can't use it, you get a vauge "cannot use it" diagnostic, but...
 - This provides an infrastructure for diagnosing other kinds of problems (e.g. 
   trying to use a private member or a static member from an instance).
 - Improves a number of cases where failed type member constraints would produce uglier
   diagnostics than a different constraint failure would.
 - Resolves a number of rdars, e.g. (and probably others):
   <rdar://problem/20294245> QoI: Error message mentions value rather than key for subscript



Swift SVN r30715
2015-07-28 07:04:22 +00:00
Chris Lattner
e94e282f2e fix a couple of testcases I failed to update
Swift SVN r30714
2015-07-28 05:17:39 +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
Jordan Rose
1edf9b3ae8 Check access for associated type requirements, too.
This is a straight-up "oops". You could always get to these typealiases via
the protocol, but like the member requirements you should have to say so.

Swift SVN r29952
2015-07-08 00:43:37 +00:00
Jordan Rose
7916aa03b8 Make sure we check access for substituted dependent types as well.
Even if a member typealias is made up of completely public types, it's still a
private typealias, and it shouldn't matter whether the member type is dependent
or not. This actually led to crashes in some cases.

rdar://problem/21408035

Swift SVN r29863
2015-07-01 23:34:37 +00:00
Joe Groff
bebfa969bd Sema: Allow 'x.init' references on metatype expressions.
If 'x.init' appears as a member reference other than 'self.init' or 'super.init' within an initializer, treat it as a regular static member lookup for 'init' members. This allows a more explicit syntax for dynamic initializations; 'self.someMetatype()' looks too much like it's invoking a method. It also allows for partial applications of initializers using 'someMetatype.init' (though this needs some SILGen fixes, coming up next). While we're in the neighborhood, do some other correctness and QoI fixes:

- Only lookup initializers as members of metatypes, not instances, and add a fixit (instead of crashing) to insert '.dynamicType' if the initializer is found on an instance.
- Make it so that constructing a class-constrained archetype type correctly requires a 'required' or protocol initializer.
- Warn on unused initializer results. This seems to me like just the right thing to do, but is also a small guard against the fact that 'self.init' is now valid in a static method, but produces a newly-constructed value instead of delegating initialization (and evaluating to void).

Swift SVN r29344
2015-06-08 04:11:28 +00:00
Chris Lattner
cf1cb14205 recommit 28958/28959, there was a testcase that didn't get updated correctly
but it was between the two revisions.


Swift SVN r28964
2015-05-23 15:50:16 +00:00
Ted Kremenek
b4b81ff657 Revert "merge assignments to UnresolvedDotExpr onto the common path,"
Backing out to fix the build.

Swift SVN r28959
2015-05-23 07:55:07 +00:00
Chris Lattner
3b64718b89 merge assignments to UnresolvedDotExpr onto the common path,
this is neutral w.r.t. diagnostics quality, but deletes a ton
of code:

 include/swift/AST/DiagnosticsSema.def |   21 ++---------
 lib/Sema/CSDiag.cpp                   |   64 ++--------------------------------
 2 files changed, 9 insertions(+), 76 deletions(-)



Swift SVN r28956
2015-05-23 05:18:59 +00:00
Chris Lattner
8853d19c2b Dramatically improve the diagnostics when a store is invalid, by taking
into account accesibility, assignments to self in a non-mutating
method (consistently), recursive components of an lvalue that makes it 
non-settable, etc.  Now we tell you what the *problem* was, instead of
just whining.

This fixes:
<rdar://problem/19370429> QoI: fixit to add "mutating" when assigning to a member of self in a struct
<rdar://problem/17632908> QoI: Modifying struct member in non-mutating function produces difficult to understand error message

in their full generality.



Swift SVN r28867
2015-05-21 05:53:36 +00:00
Chris Lattner
df19d03eb7 When diagnosing invalid assignment errors, dig into the constraint system to see
if it has already resolved a member binding of an UnresolvedDotExpr.  This allows
us to give tailored diagnostics to indicate whether the destination is not an lvalue
because the property itself was immutable or when the base is immutable.

In addition to improved diagnostics, this allows us to fixit hint "let" to "var" on
property definitions, and we can even go so far as to fixit hint insert 'mutating' on 
the enclosing func decl when self is the problem.

This fixes the non-subscript cases of:
<rdar://problem/17632908> QoI: Modifying struct member in non-mutating function produces difficult to understand error message
<rdar://problem/19370429> QoI: fixit to add "mutating" when assigning to a member of self in a struct
<rdar://problem/20234955> QoI: Error message for assigning to 'let' fields should say that the error is due to a 'let' binding

Subscript cases to follow.



Swift SVN r28854
2015-05-20 22:18:52 +00:00
Dmitri Hrybenko
f46f16ae82 stdlib: implement new print() API
rdar://20775683

Swift SVN r28309
2015-05-08 01:37:59 +00:00
Jordan Rose
13e8137113 [test] Add more testability tests, including execution tests.
Swift SVN r26785
2015-04-01 01:12:25 +00:00
Jordan Rose
eb4ade4462 Honor @testable import for internal decls in ValueDecl::isAccessibleFrom.
We can now use internal declarations safely and correctly in source files!
The remaining work is to make sure testable imports work reliably through
modules, which is important for debugging unit tests.

It's also possible this work will affect compile time, but for the most
part we don't have large quantities of internal declarations that are
being ignored, and some day we will strip them out of non-testable modules
altogether.

Part of rdar://problem/17732115

Swift SVN r26633
2015-03-27 16:36:46 +00:00
Doug Gregor
9271a24a92 Introduce a protocol conformance registry for nominal types.
(Note that this registry isn't fully enabled yet; it's built so that
we can test it, but has not yet taken over the primary task of
managing conformances from the existing system).

The conformance registry tracks all of the protocols to which a
particular nominal type conforms, including those for which
conformance was explicitly specified, implied by other explicit
conformances, inherited from a superclass, or synthesized by the
implementation.

The conformance registry is a lazily-built data structure designed for
multi-file support (which has been a problematic area for protocol
conformances). It allows one to query for the conformances of a type
to a particular protocol, enumerate all protocols to which a type
conforms, and enumerate all of the conformances that are associated
with a particular declaration context (important to eliminate
duplicated witness tables).

The conformance registry diagnoses conflicts and ambiguities among
different conformances of the same type to the same protocol. There
are three common cases where we'll see a diagnostic:

1) Redundant explicit conformance of a type to a protocol:

    protocol P { }
    struct X : P {  }
    extension X : P { } // error: redundant explicit conformance

2) Explicit conformance to a protocol that collides with an inherited
  conformance:

    protocol P { }
    class Super : P { }
    class Sub : Super, P { } // error: redundant explicit conformance

3) Ambiguous placement of an implied conformance:

    protocol P1 { }
    protocol P2 : P1 { }
    protocol P3 : P1 { }

    struct Y { }
    extension Y : P2 { }
    extension Y : P3 { } // error: ambiguous implied conformance to 'P1'

  This happens when two different explicit conformances (here, P2 and
  P3) placed on different declarations (e.g., two extensions, or the
  original definition and other extension) both imply the same
  conformance (P1), and neither of the explicit conformances imply
  each other. We require the user to explicitly specify the ambiguous
  conformance to break the ambiguity and associate the witness table
  with a specific context.

Swift SVN r26067
2015-03-12 21:11:23 +00:00
Jordan Rose
c9eeed3e2d Remove staging option -enable-private-discriminators.
Private discriminators for everybody!

Swift SVN r25997
2015-03-11 23:07:44 +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
John McCall
8c303ef7a6 Representational changes towards get-and-mutableAddress
properties.

The main design change here is that, rather than having
purportedly orthogonal storage kinds and has-addressor
bits, I've merged them into an exhaustive enum of the
possibilities.  I've also split the observing storage kind
into stored-observing and inherited-observing cases, which
is possible to do in the parser because the latter are
always marked 'override' and the former aren't.  This
should lead to much better consideration for inheriting
observers, which were otherwise very easy to forget about.
It also gives us much better recovery when override checking
fails before we can identify the overridden declaration;
previously, we would end up spuriously considering the
override to be a stored property despite the user's
clearly expressed intent.

Swift SVN r22381
2014-09-30 08:39:38 +00:00
Jordan Rose
8770a8f6f7 [Sema] Allow "redeclarations" within a module if both declarations are private.
While we could allow declarations with the same name and type if all but one
are private, it feels a bit subtle that one declaration at top-level scope can
shadow another declaration at top-level scope elsewhere in the module. Let's
start with this for now.

Currently guarded by -enable-private-discriminators.

Part of rdar://problem/17632175

Swift SVN r21602
2014-08-30 00:17:24 +00:00
Jordan Rose
5c1e9d7d36 [Accessibility] Store setter accessibility explicitly.
Previously, we were just storing setter accessibility via the accessibility
level on the setter function. However, some Stored properties never actually
have a setter synthesized, which led to the compiler dropping the setter
accessibility at serialization time. Rather than try to hack up something
clever, just store the setter accessibility explicitly in every
AbstractStorageDecl. (We still only serialize it for VarDecls, because
settable SubscriptDecls always have setter functions.)

<rdar://problem/17816530>

Swift SVN r20598
2014-07-26 22:43:54 +00:00
Jordan Rose
0c28c9c220 Add a test verifying that conformance checking respects access control.
<rdar://problem/17632316>

Swift SVN r20503
2014-07-24 17:58:23 +00:00
Jordan Rose
6d2afe799b [Accessibility] Observing overrides must be able to access the base setter.
Otherwise, the subclasser isn't really supposed to know that the base
property is internally settable. Overriding such a property isn't likely
to do much good (because the base class won't call your overridden setters),
but allowing observation leaks information about the base class.

<rdar://problem/17632360>

Swift SVN r20440
2014-07-23 23:07:14 +00:00
Jordan Rose
14196453cc Add a special diagnostic when a type has no accessible initializers.
Rather than just saying "'Foo' is not constructible with '()'", say
"'Foo' cannot be constructed because it has no accessible initializers",
which would help framework authors realize what they did wrong.

<rdar://problem/17717714>

Swift SVN r20232
2014-07-20 19:52:24 +00:00
Jordan Rose
2d3ae53222 Add a test that "super.foo" doesn't get around access control.
No functionality change.

Swift SVN r19971
2014-07-15 04:57:02 +00:00
Jordan Rose
5b80dc3d44 Respect accessibility for scoped imports.
"import var Foo.bar" should error if "Foo.bar" is not public.

Swift SVN r19747
2014-07-09 22:10:20 +00:00
Jordan Rose
76b24307a4 [Accessibility] Add some basic tests for member lookup.
This has been working for a while; there just weren't explicit tests for it.

Swift SVN r19621
2014-07-07 18:39:36 +00:00
Jordan Rose
a7b563855e Add a mode in which access control is respected for module-scope lookups.
This applies to both qualified and unqualified lookups, and is controlled
by the -enable-access-control and -disable-access-control flags. I've
included both so that -disable-access-control can be put into specific tests
that will eventually need to bypass access control (e.g. stdlib unit tests).
The default is still -disable-access-control.

Swift SVN r19146
2014-06-24 21:32:21 +00:00