Commit Graph

1005 Commits

Author SHA1 Message Date
Robert Widmann
b79fa44da5 Merge pull request #3878 from CodaFi/decltype
[SE-0096] Implement type(of:)
2016-07-29 18:05:01 -07:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07:00
Robert Widmann
80fb5c1c5a Remove usage of getMetatypeLoc() 2016-07-29 16:59:14 -07:00
Robert Widmann
4f465224ea Polish off uses of dynamicType in tests 2016-07-29 16:59:14 -07:00
Michael Ilseman
c37751ae96 [noescape by defaul] make noescape the default
This flips the switch to have @noescape be the default semantics for
function types in argument positions, for everything except property
setters. Property setters are naturally escaping, so they keep their
escaping-by-default behavior.

Adds contentual printing, and updates the test cases.

There is some further (non-source-breaking) work to be done for
SE-0103:

- We need the withoutActuallyEscaping function
- Improve diagnostics and QoI to at least @noescape's standards
- Deprecate / drop @noescape, right now we allow it
- Update internal code completion printing to be contextual
- Add more tests to explore tricky corner cases
- Small regressions in fixits in attr/attr_availability.swift
2016-07-29 13:49:08 -07:00
Joe Groff
2a5b9d6559 Remove now-dead _isBridgedToObjectiveC() declarations in _ObjectiveCBridgeable conformers. 2016-07-28 12:29:47 -07:00
Slava Pestov
f8f6d61d19 Fixes for typealiases involving generics (#3811)
* Serialization: Another fix for generic typealiases

Fixes <https://bugs.swift.org/browse/SR-1889>.

* Sema: Fix FindCapturedVars to look through typealiases

Fixes <https://bugs.swift.org/browse/SR-1781>.
2016-07-27 21:35:37 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
David Farler
4a57e647e6 Merge pull request #3762 from bitjammer/se-0081-diagnostic-and-crashes
[SE-0081] Warn on deprecated where clause inside angle brackets
2016-07-26 09:09:30 -07:00
David Farler
7bfaeb57f1 [SE-0081] Warn on deprecated where clause inside angle brackets
and provide a fix-it to move it to the new location as referenced
in SE-0081.

Fix up a few stray places in the standard library that is still using
the old syntax.

Update any ./test files that aren't expecting the new warning/fix-it
in -verify mode.

While investigating what I thought was a new crash due to this new
diagnostic, I discovered two sources of quite a few compiler crashers
related to unterminated generic parameter lists, where the right
angle bracket source location was getting unconditionally set to
the current token, even though it wasn't actually a '>'.
2016-07-26 01:41:10 -07:00
Jordan Rose
ebdee21464 Handle top-level vars' and closure params' access specially.
Parameters are normally given 'private' access, because they can only
be referred to within the body of the owning function. However,
single-expression closures allow a parameter to appear in a constraint
system in the containing context. Mark closure parameters as
'fileprivate' instead.

Similarly, 'private' at the top level is normally equivalent to
'fileprivate', but not for a decl that appears within top-level
imperative code, which has a TopLevelCodeDecl context. This currently
only happens for bindings in a top-level 'guard' statement; mark
these variables and constants as 'fileprivate' as well.

More progress on SE-0025 ('private' and 'fileprivate').
2016-07-25 20:20:58 -07:00
Joe Groff
d2e1c4a662 Update PrintAsObjC, NameBinding, attr, decl, expr tests for id-as-Any. 2016-07-25 06:40:35 -07:00
Chris Lattner
842d6777d9 enhance a few diagnostics to include the non-optional type name. 2016-07-23 17:30:03 -07:00
Chris Lattner
d138290448 Produce warnings when implicit optional promotions are introduced in some
common standard library operators.  This is progress towards:
<rdar://problem/27457457> [Type checker] Diagnose unsavory optional injections

but there is more work to be done here.
2016-07-23 16:03:41 -07:00
Mark Lacey
3ba204694e Do not suppress optional coercion in operators with a nil-literal operand.
This is the hack that has been used to reject things like:
  var i: Int = ...
  if i == nil { }
in the past.

The hack is inconsistent with normal treatment of mixed optional &
non-optional operands, and will be replaced with a warning instead of
treating it as a failure to type check.

There is still a case that we still fail type checking on -
Unsafe*Pointer<> compares to nil. That will be addressed by a separate
commit.

The new warning will be addressed by rdar://problem/27457457. When the
new warnings are updated the test cases modified here will again need to
be updated based on the text of the new warning.
2016-07-21 22:39:33 -07:00
Rintaro Ishizaki
bdaa9cb689 [Parse] Improve fix-it for deprecated protocol<...> syntax
`protocol<A,B>` case, used to fixed-it as `A &B`, that is illegal.

Instead of removing angles and replacing commas, replace whole expession
with new syntax.
2016-07-21 14:49:02 +09:00
Rintaro Ishizaki
97c325f908 [Parse] Improve diagnostic for deprecated protocol<...> syntax (#3631)
* Don't emit deprecated warnings for incomplete protocol<...>.
  E.g: `func fn(x: protocol<P) {}`
* Different message for single protocol compostion.
  E.g: `typealias MyError = protocol<Error>`
2016-07-21 13:44:08 +09:00
John McCall
445ff27082 Basic Sema support for covariant collection casting.
The previous revert was required because of missing stdlib support.
I believe that support is now present, at least so that this won't
crash on Linux.
2016-07-19 14:35:03 -07: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
7b9e5de7b7 [SE-0095] simplifyTypeExpr for composition expressions
Also adds:
- Any is caught before doing an unconstrained lookup, and the
protocol<> type is emitted
- composition expressions can be handled by
`PreCheckExpression::simplifyTypeExpr` to so you can do lookups like (P
& Q).self
- Fixits corrected & new tests added
- Typeref lowering cases should have been optional
- This fixes a failing test case.
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
Michael Gottesman
a047bb7564 Revert "Fix the build."
This reverts commit dc24c2bd34.

Turns out Chris fixed the build but when I was looking at the bots, his fix had
not been tested yet, so I thought the tree was still red and was trying to
revert to green.
2016-07-17 16:29:18 -07:00
Michael Gottesman
dc24c2bd34 Fix the build.
This reverts commit b4cba58330.
This reverts commit a602927c75.
This reverts commit 55fbe5a763.
2016-07-17 16:17:15 -07:00
Chris Lattner
55fbe5a763 Remove Boolean as a special, privileged type used by Sema, and instead
use the concrete Bool type.  This eliminates a bunch of complexity and
makes diagnostics more concrete.
2016-07-17 15:14:24 -07:00
Chris Lattner
a0d34852bb Revert "Fix the build."
This reverts commit 932fe9d6b9.
2016-07-17 12:35:42 -07:00
Michael Gottesman
932fe9d6b9 Fix the build.
This reverts commit 4242af7503.
This reverts commit 76cf339694.
This reverts commit e97ed133a8.
This reverts commit 66961fcda8.
2016-07-17 01:02:48 -07:00
Chris Lattner
76cf339694 Implement the first half of SE-0109: Remove the Boolean protocol
This removes conformance of DarwinBool and ObjCBool to the Boolean protocol,
and makes the &&/||/! operators be concrete w.r.t. Bool instead of abstract
on Boolean.

This fixes some outstanding bugs w.r.t diagnostics, but exposes some cases
where an existing diagnostic is not great.  I'll fix that in a later patch
(tracked by rdar://27391581).
2016-07-16 23:23:45 -07:00
Mishal Shah
8a660e5b85 Revert "Basic Sema support for covariant collection casting."
Ubuntu 14.04 and 15.10 bots failing due to this commit.

This reverts commit 4b6a57292f.
2016-07-14 12:35:40 -07:00
John McCall
4b6a57292f Basic Sema support for covariant collection casting. 2016-07-13 19:13:02 -07:00
Mark Lacey
86c97dfbb5 Merge pull request #3483 from rudkx/fix-nil-comparisons
Improve diagnostics for comparisons to nil.
2016-07-13 11:50:06 -07:00
Mark Lacey
1d9fde8f5c Improve diagnostics for comparisons to nil.
As implemented the diagnostic specific to nil was only firing when nil
was on the right hand side.
2016-07-12 17:21:12 -07:00
Robert Widmann
f97e5dcb0e [SE-0115][1/2] Rename *LiteralConvertible protocols to ExpressibleBy*Literal. This
change includes both the necessary protocol updates and the deprecation
warnings
suitable for migration.  A future patch will remove the renamings and
make this
a hard error.
2016-07-12 15:25:24 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
Alex Hoppen
c8ec2c0a2b [Diag] Fixit when trying to pattern match Optional and non-Optional
If the variable to be matched is an optional and the match partner is
non-optional, provide a fixit that inserts a '?' after the match partner
2016-07-11 16:27:57 +02:00
Alex Hoppen
fc4216e94b [Sema] Don't suggest fixits that try to force unwrap implicit $match
Check if a variable is actually spelled out in code before suggesting a
fixit that adds a force unwrap to it

This fixes SR-1827
2016-07-11 16:27:57 +02:00
Rintaro Ishizaki
4bf1c34f80 [Parse/Sema][SR-1672] Improve diagnostics for trailing closures in stmt-condition (#3184)
Fix-it suggests normal argument expression, instead of of enclosing whole
expression with parens.

* Moved diagnostic logic to Sema, because we have to add correct argument
  label for the closure.

    if arr.starts(with: IDs) { $0.id == $2 } { ... }
                           ~~^
                           , isEquivalent:  )

* We now accept trailing closures for each expressions and right before `where`
  clause, as well as closures right before the body.

    if let _ = maybeInt { 1 }, someOtherCondition { ... }
                       ~^
                       (     )

    for let x in arr.map { $0 * 4 } where x != 0 { ... }
                        ~^
                        (          )
2016-07-09 12:51:51 +09:00
Chris Lattner
ffcafd7c00 fix the AST printer to stop omitting parens around "simple enough" parameter
lists.
2016-07-02 20:24:58 -07:00
Xi Ge
1e85e1bcd2 Revert "[Fixit] Add a fixit for converting non-trailing closures to trailing closures (#3317)"
This patch needs some polish to fix more false positives found by @rintaro and @lattner
2016-07-02 09:39:07 -07:00
Xi Ge
1886b4ab56 [Fixit] Add a fixit for converting non-trailing closures to trailing closures (#3317)
* [Fixit] Add a fixit for converting non-trailing closures to trailing closures.

* [test] Update test to reflect the added note about converting to trailing closures.
2016-07-02 08:11:58 -07:00
John McCall
3a23c08549 Implement typo correction for #keypath expressions. 2016-07-01 15:09:49 -07:00
Slava Pestov
f0d2d35341 Merge pull request #3229 from ahoppen/SR-1827-change-syntax
Make #selector a primary expression
2016-06-27 23:06:56 -07:00
Slava Pestov
c870052520 Sema: Give capture analysis ability to sniff out uses of dynamic 'Self'
This also adds some tests for the existing generic parameter
capture logic, which was only tested as part of SILGen tests
until now.

Also, move capture analysis into a new TypeCheckCaptures.cpp file.
2016-06-27 18:37:52 -07:00
Alex Hoppen
884af9ccab [Parser] Make #selector a primary expression
This allows #selector to be followed by a trailing `?` in case statements as reported in SR-1827
2016-06-27 22:11:58 +02:00
Harlan
cca7dcab52 Added fixit to remove empty argument for non-function calls (#3196) 2016-06-26 17:06:26 -07:00
Rintaro Ishizaki
57df1faaf3 [Lexer] Add test case for erroneous hex number literal (#3162) 2016-06-24 11:14:04 +09:00
Rintaro Ishizaki
0d2da2050c [Lexer] Add a few test cases for hex number literal 2016-06-22 16:25:03 +09:00
Rintaro Ishizaki
a5eed3828a [Lexer][SR-1724] Handle hex letters after '.' on hex number literal
The following case used to emit an error:

  extension Int {
    var asUiColor: UIColor { ... }
  }

  0xfff.asUiColor
2016-06-22 13:07:41 +09:00
Rintaro Ishizaki
1bdce7ced6 [lit] Add substitutions: %utils and %line-directive
%utils => ${SWIFT_SOURCE_DIR}/utils
%line-directive => ${SWIFT_SOURCE_DIR}/utils/line-directive
2016-06-11 02:41:15 +09:00
Robert Widmann
054f2ffa1a Resolve SR-1594 2016-05-31 16:49:11 -07:00
Joe Pamer
39e7c77a47 When generating constraints for subscript expressions, look beyond array
slice types when deciding whether or not to create a fresh type variable
for the array's base expression. (rdar://problem/2639230)
2016-05-23 15:56:20 -07:00