Commit Graph

42 Commits

Author SHA1 Message Date
Doug Gregor
761b0aa98c Allow existential opening for parameters of optional type. 2022-09-27 13:08:36 -07:00
Holly Borla
6e8a581b42 [LangOptions] Remove the option to enable/disable implicit existential
opening.
2022-06-27 18:03:20 -07:00
Doug Gregor
c76a99ba02 [SE-0352] Enable implicit opening of existentials by default 2022-04-20 17:51:04 -07:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Pavel Yaskevich
f24e5dbd26 [Diangostics] NFC: Adjust test-cases to expect that "type cannot conform" diagnostic has a note 2020-10-27 14:54:07 -07:00
Onyekachi Ezeoke
434607d004 fix broken tests 2020-06-27 05:53:47 +01:00
Pavel Yaskevich
ec3b783380 [Diagnostics] Improve diagnostic for invalid conversion to AnyObject 2020-01-29 00:37:39 -08:00
Holly Borla
ea7c13e506 [Diagnostics] For now, don't diagnose layout requirement failures
in MissingConformanceFailure::diagnoseTypeCannotConform.
2019-10-18 14:00:18 -07:00
Holly Borla
ef0ecc41e5 [ConstraintSystem] Diagnose missing AnyObject conformance using
the MissingConformance constraint fix.
2019-10-16 20:38:00 -07:00
Holly Borla
7687293b7b [Diagnostics] Adjust the description of existential types for the
type_cannot_conform diagnostic message.
2019-09-17 11:52:43 -07:00
Holly Borla
2a7e0099d2 [Diagnostics] Add notes for the type_cannot_conform error that point
to the declaration that requires protocol conformance.
2019-09-17 09:22:07 -07:00
Holly Borla
40985b6eb7 [Diagnostics] Generalize the "protocol type cannot conform" error to
work for all types that cannot conform to protocols.
2019-09-13 14:51:17 -07:00
Pavel Yaskevich
f15e17a629 [Sema] NFC: reword "only concrete types can conform to protocols" diagnostic 2018-08-03 14:27:00 -07:00
Pavel Yaskevich
c2bf3d5ba9 [TypeChecker] NFC: Fix all of the diagnostics improved by conformance tracking 2018-08-02 21:55:16 -07:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Doug Gregor
405079984f Another test whose diagnostics improved 2018-01-25 17:31:15 -08:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Brian King
29c1fc472b Generate an error message on protocol extensions with the final attribute. 2017-03-09 14:18:39 -05:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Joe
3938d5682a [SE-0095] [Runtime], [Demangler], & AST printer updated to new composition syntax
- All parts of the compiler now use ‘P1 & P2’ syntax
- The demangler and AST printer wrap the composition in parens if it is
in a metatype lookup
- IRGen mangles compositions differently
    - “protocol<>” is now “swift.Any”
    - “protocol<_TP1P,_TP1Q>” is now “_TP1P&_TP1Q”
- Tests cases are updated and added to test the new syntax and mangling
2016-07-19 12:01:37 -07:00
Joe
a6dad0091b [SE-0095] Initial parsing implementation for '&' composition syntax
This commit defines the ‘Any’ keyword, implements parsing for composing
types with an infix ‘&’, and provides a fixit to convert ‘protocol<>’

- Updated tests & stdlib for new composition syntax
- Provide errors when compositions used in inheritance.
Any is treated as a contextual keyword. The name ‘Any’
is used emit the empty composition type. We have to
stop user declaring top level types spelled ‘Any’ too.
2016-07-19 12:01:02 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Maxim Moiseev
7e2466c14e CollectionType => Collection 2015-12-09 17:12:48 -08:00
Dmitri Gribenko
2cf172160c Rename SequenceType.Generator associated type to SequenceType.Iterator 2015-12-09 17:11:05 -08:00
Chris Lattner
505ff58cdb Make conversion diagnostics between as? and as! expression consistent by allowing
diagnoseGeneralConversionFailure() to handle them (instead of it handling as? but
special code handling as!).

As part of this, enhance things so we get error messages about both the problem, 
and the overall type involved (when they're different) e.g.:

  if let s = setD as? Set<BridgedToObjC> { }

error: 'ObjC' is not a subtype of 'DerivesObjC'
note: in cast from type 'Set<DerivesObjC>' to 'Set<BridgedToObjC>'

This also finally fixes the case in test/Generics/existential_restrictions.swift



Swift SVN r31299
2015-08-18 18:00:37 +00:00
Chris Lattner
6ab8d49b98 fix radar number in comment, nfc.
Swift SVN r31061
2015-08-06 21:08:38 +00:00
Chris Lattner
072868d3f6 Simplify the implementation of visitCoerceExpr/visitForcedCheckedCastExpr,
and diagnoseGeneralConversionFailure().  The previous approach of trying
to dig into anchors would often lead to complaining about types at 
different levels in the same diagnostic, and the complexity of the former
code isn't needed now that other changes have landed.



Swift SVN r31036
2015-08-06 00:58:55 +00:00
Chris Lattner
4a5be366c2 add a new ContinueAfterFailures default argument to ConstraintSystem::simplify,
and use it in the diagnostics path (only!) to revisit active constraints that
are left in the system after a failure is found.  This improves a number of 
otherwise sad diagnostics in the testsuite and resolves rdar://22083115.

The one QoI regression (in throwing_functions.swift) is now tracked by 22158167.



Swift SVN r31027
2015-08-05 20:57:39 +00:00
Chris Lattner
9d9b8aaf35 move protocol conformance errors away from being diagnosed as a Failure, instead
putting it into the expr diagnostics path, allowing more contextual messages.


Swift SVN r30920
2015-08-01 18:31:59 +00:00
Chris Lattner
97e6a50148 Start using contextual information from function calls to diagnose issues in their
argument.  For now we start with some of the most simple cases: single argument 
calls.  This dramatically improves the QoI for error messages in argument lists,
typically turning a error+note combo into a single specific error message.

Some minor improvements coming (and also generalizing this to n-ary calls), but it 
is nice that all the infrastructure is starting to come together...



Swift SVN r30905
2015-08-01 04:37:52 +00:00
Ben Langmuir
c1a2955ef6 Revert r30787, r30789, r30795, r30796, r30797
r30787 causes our tests to time out; the other commits depend on r30787.

Revert "revert part of my previous patch."
Revert "Produce more specific diagnostics relating to different kinds of invalid"
Revert "add a testcase, nfc"
Revert "- Reimplement FailureDiagnosis::diagnoseGeneralMemberFailure in terms of"
Revert "Fix places in the constraint solver where it would give up once a single "

Swift SVN r30805
2015-07-30 17:44:22 +00:00
Chris Lattner
4fb19ada2b Fix places in the constraint solver where it would give up once a single
constraint failed, leaving a bunch of other solvable constraints laying 
around in the system as inactive.

This is a problem for diagnostics emission, because it turns around and
reaches into the constraint system for some inactive constraint, assuming
that anything left could not be solved.  The constraint system attempted to
solve this by taking the first failure and putting it into the failedConstraint
with the intention of driving diagnostics, but just because it happened to fail
first in constraint-solver-worklist-order doesn't mean it is the most pertinent
one to diagnose.



Swift SVN r30787
2015-07-30 05:08:50 +00: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
Jordan Rose
ee08177141 Tweak diagnostics for non-self-conforming protocols.
Before:
- protocol type 'Listener' does not conform to protocol 'Listener' because
  'Listener' is not declared @objc
- protocol type 'Listener' does not conform to protocol 'Listener' because
  'Listener' defines static methods

After:
- using 'Listener' as a concrete type conforming to protocol 'Listener' is
  not supported
- 'Listener' cannot be used as a type conforming to protocol 'Listener'
  because 'Listener' has static requirements

I removed the mention of '@objc' even though @objc protocols are more freely
self-conforming because it was confusing people working with pure Swift code.
Making this actually work for pure Swift protocols is tracked by
rdar://problem/21341337.

This also fixes a few cases where we were emitting this message even for
two completely unrelated protocols.

rdar://problem/21525618

Swift SVN r30698
2015-07-27 21:43:49 +00:00
Chris Lattner
467cd07968 Two changes:
- Improve handling of if_expr in a couple of ways: teach constraint simplification
   about IfThen/IfElse and teach CSDiags about the case when the cond expr doesn't match
   BooleanType.  This is rarely necessary, but CSDiags is all about cornercases, and this
   does fix a problem in a testcase.
 - Be a bit more specific about the constraint failure kind (e.g. say subtype) and when
   we have a protocol conformance failure, emit a specific diagnostic about it, instead of
   just saying that the types aren't convertible.




Swift SVN r30650
2015-07-26 05:31:12 +00:00
Chris Lattner
0a3197390f Various changes:
- Don't "aka" a Builtin.Int2123 type, it just makes a bad diagnostic worse.
 - Split out the predicate that CSDiag uses to determine what a conversion
   constraint is to a helper fn, and add subtype constraints to the mix.
 - Move eraseTypeData into CSDiag (its own client) as a static function.
 - Make eraseTypeData be a bit more careful about literals, in an attempt to
   improve diagnostics when literals get re-type-checked.  It turns out that
   this still isn't enough as shown by the regression on the 
   decl/func/default-values.swift testcase, and the 
   Constraints/dictionary_literal.swift testcase where one bad diagnostic turns
   into another different one, but I'll keep working on it.
 - Beef up diagnoseContextualConversionError and the caller to it to be more
   self contained and principled about the conversion constraints it digs out
   of the system.  This improves the diagnostics on a couple of cases.



Swift SVN r30642
2015-07-26 00:29:40 +00:00
Chris Lattner
5d3dc0d77b Now that sufficient complexity is pushed into the right corners of the compiler,
we can start taking advantage of ambiguously typed subexpressions in CSDiags.  We
start by validating the callee function of ApplyExprs, which substantially improves
our abilities to generate precise diagnostics about malformed calls.

This is the minimal introduction of this concept to CSDiags, a lot of refactoring
is yet to come, however, this is enough to resolve:

<rdar://problem/21080030> Bad diagnostic for invalid method call in boolean expression
<rdar://problem/21784170> Incongruous `unexpected trailing closure` error in `init` function which is cast and called without trailing closure.

one of the testcases from:
<rdar://problem/20789423> Unclear diagnostic for multi-statement closure with no return type

and a bunch of other places where we got weird "unexpected trailing closure" 
diagnostics that made no sense.  As usual, it is two steps forward and one step back,
as this exposed some other weird latent issues like:
<rdar://problem/21900971> QoI: Bogus conversion error in generics case




Swift SVN r30429
2015-07-21 01:06:55 +00:00
Slava Pestov
9a65927f40 Sema: Another fix for protocol self-conformance
It looks like we were checking in the wrong place, as a result we didn't
catch stuff like

class G<T : AnyObject> {}
_ = G<P>()

This would crash later in IRGen.

Make the conformsToProtocol() check do the right thing, and remove some
other miscellaneous diagnostics in the process. Also, make the
"type 'T' does not conform to protocol 'P'" diagnostic a bit more
detailed.

Unfortunately in a few instances we lose a more descriptive diagnostic to
a general 'cannot invoke 'foo' with argument list of type 'T'' error. The
argument matching diagnostics need to be addressed anyway though.

Fixes <rdar://problem/20311619>.

Swift SVN r29737
2015-06-26 07:29:56 +00:00
Slava Pestov
322f58d8b1 Sema: Tighten up existential vs generic type parameter distinction
Rename existentialConformsToSelf() to existentialTypeSupported(). This
predicate is the "protocol has no Self or associated type requirements"
check, which is a looser condition than self-conformance. This was being
tested to see if the user could refer to the protocol via an existential
type.

The new existentialConformsToSelf() now checks for protocol being @objc,
and for the absence of static methods. This is used as part of the
argument type matching logic in matchType() to determine if the
existential can be bound to a generic type parameter.

The latter condition is stricter, for two reasons:

1) We allow binding existentials to multiple type parameters all sharing
   the same generic type parameter T, so we don't want the user to be
   able to see any static methods on T.
2) There is an IRGen limitation whereby only existentials without witness
   tables can be passed in this manner.

Using the above, the representsNonTrivialGenericParameter() function
has been renamed to canBindGenericParamToExistential(). It now allows
an existential type to be bound to a generic type parameter only under
the following circumstances:

A) If the generic type parameter has no conformances, the match is allowed.

B) If the generic type parameter has at least one conformance, then all
   of the conformances on the generic type parameter must be
   existentialConformsToSelf() (condition 1 above), and all conformances
   on the existential must be @objc (condition 2 above).

Fixes <rdar://problem/18378390> and <rdar://problem/18683843>, and lays
the groundwork for fixing a few other related issues.

Swift SVN r29337
2015-06-07 10:16:21 +00:00
Doug Gregor
e2bec4377b Don't allow existentials to be used where we need a witness table.
If we end up trying to form a substitution where the replacement type
is an existential and there is a conformance to a non-@objc protocol
(i.e., a conformance where a witness table is required), complain in
Sema rather than crashing in IRGen. Fixes rdar://problem/21087341, but
the existential/generic interaction is still quite broken.

Swift SVN r29133
2015-05-29 05:02:18 +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
Doug Gregor
8cf718f9f6 Don't allow a generic parameter with a non-@objc protocol requirement to bind to an existential.
We don't properly open up the existential to make this work, which
leads to an IRGen crash. Reject the uses of generics that would cause
such a crash rdar://problem/17491663.


Swift SVN r21946
2014-09-15 17:36:26 +00:00