Commit Graph

35 Commits

Author SHA1 Message Date
Chris Willmore
03a6190a1f <rdar://problem/19031957> Change failable casts from "as" to "as!"
Previously the "as" keyword could either represent coercion or or forced
downcasting. This change separates the two notions. "as" now only means
type conversion, while the new "as!" operator is used to perform forced
downcasting. If a program uses "as" where "as!" is called for, we emit a
diagnostic and fixit.

Internally, this change removes the UnresolvedCheckedCastExpr class, in
favor of directly instantiating CoerceExpr when parsing the "as"
operator, and ForcedCheckedCastExpr when parsing the "as!" operator.

Swift SVN r24253
2015-01-08 00:33:59 +00:00
Chris Lattner
3e41339cb2 rename @__noescape to @noescape, now that it is a generally visible feature,
wrapping up rdar://16323038.  Pieces still remaining are a Clang attribute+
importer support for it, plus adoption in the stdlib (tracked by other radars).


Swift SVN r24223
2015-01-06 22:54:25 +00:00
Chris Lattner
cc68e77f9a adopt @__noescape in a couple of places. This isn't required today, but if/when
@autoclosure starts implying noescape, it will be needed to indicate that the 
autoclosure isn't actually escaped.




Swift SVN r24212
2015-01-06 06:37:49 +00:00
Dmitri Hrybenko
ce9f5887b7 Revert "adopt @__noescape in various places in the stdlib, making sure to cover all of the "
This reverts commit r24141, it broke tests:

Failing Tests (2):
    Swift :: parser/parse_stdlib.sil
    Swift :: stdlib/AssertDiagnostics.swift

Swift SVN r24147
2014-12-24 05:51:51 +00:00
Chris Lattner
a86c7902ae adopt @__noescape in various places in the stdlib, making sure to cover all of the
@transparent functions that take a closure.  NFC since these always get inlined
at the moment anyway.



Swift SVN r24141
2014-12-24 01:30:00 +00:00
Chris Lattner
b8596ffccb move the stdlib to the new syntax for @autoclosure attribute.
Swift SVN r24048
2014-12-20 00:16:36 +00:00
Dmitri Hrybenko
397d2fb8c3 stdlib: coding style: when colon specifies is-a relationship, we put
spaces on both sides of it

Swift SVN r23935
2014-12-15 06:55:30 +00:00
Chris Hanson
b644ff5888 XCTAssert(true, "Pass") crashes in Swift
Instead of trying to bridge NSDictionary to [String:String], XCTest needs to
just request the objects from the NSDictionary as String.

Also, move the unwrapping of the optional from the might-throw block such that
it only happens when the block hasn't thrown. Unwrapping the optional if the
block has thrown would crash, because the optional would still be unset.

Addresses <rdar://problem/17952584>.

Swift SVN r21119
2014-08-08 22:51:30 +00:00
Chris Hanson
91069e1647 Get XCTAssertEqual working with [T] and [T:U]
XCTest's equality assertions need overrides in order to work with Array<T> and
Dictionary<T,U>.

Addresses <rdar://problem/17257148>.

Swift SVN r20993
2014-08-04 02:10:03 +00:00
Chris Hanson
63a37b29a5 XCTest assertions will eventually EXC_BAD_ACCESS
The SPI that XCTest exposes to the overlay has Objective-C semantics,
while anything exposed to Swift code via @asmname needs Swift semantics.

Add a bridge to the overlay that handles this adaptation.

Addresses <rdar://problem/17408423>.

Swift SVN r20932
2014-08-02 00:17:28 +00:00
Chris Hanson
666e4ee2f3 Further work on handling exceptions in XCTest
Rather than use a header file and -import-objc-header, use @asmname and
@objc_block to tell the overlay about the Objective-C function used to
capture exceptions.

Further addresses <rdar://problem/16453199>.

Swift SVN r20929
2014-08-01 23:36:48 +00:00
Chris Hanson
76631d14bd Catch exceptions thrown during assertions.
Since Swift itself has no exception support, use an Objective-C helper function
to evaluate a block and return an NSDictionary indicating whether an exception
was thrown out of that block (and if so, which exception).

Addresses <rdar://problem/16453199>.

Swift SVN r20880
2014-08-01 02:45:39 +00:00
Greg Parker
1167c1722d Fix XCTest build.
Swift SVN r20813
2014-07-31 05:37:24 +00:00
Chris Hanson
867429b0f4 Make XCTAssertEqualWithAccuracy work with CGFloat
Now that CGFloat is a peer of Float and Double, we need to add appropriate handling
to it for XCTAssertEqualWithAccuracy.

Addresses <rdar://problem/17762421>.

Swift SVN r20800
2014-07-31 01:36:32 +00:00
Joe Pamer
1fec0afbd0 Disallow value-to-optional conversions between argument and parameter types when resolving overloads for operators applied to nil literal operands.
This is a targeted fix to address rdar://problem/16848110 ("Disallow non-optionals to be compared to nil") and its associated dupes.

Swift SVN r20716
2014-07-29 23:24:36 +00:00
Dmitri Hrybenko
d14f17beef Change 'getLogicValue()' into a property 'boolValue'; change
'getArrayBoundValue()' into a property 'arrayBoundValue'.

rdar://17156123


Swift SVN r20304
2014-07-22 12:08:10 +00:00
Doug Gregor
b502010365 s/auto_closure/autoclosure in XCTest
Swift SVN r20255
2014-07-21 15:36:57 +00:00
Chris Hanson
877367add5 Have XCTest use string interpolation everywhere.
Instead of using reflect(), use string interpolation now that it should work everywhere.

Addresses <rdar://problem/17415068>.

Swift SVN r20061
2014-07-16 23:58:07 +00:00
Chris Hanson
c3c1489a1c Declare access control for XCTest overlay.
Now that Swift has an access control model, we need to apply it to the XCTest overlay.

This is handy in that it lets us hide some implementation details of the overlay.

Addresses <rdar://problem/17653535>.

Swift SVN r19989
2014-07-15 23:03:29 +00:00
Dave Abrahams
bf55e6b4ed [stdlib] s/FloatingPointNumberType/FloatingPointType/
Swift SVN r19887
2014-07-13 01:00:51 +00:00
Dave Abrahams
cbcf9aba21 s/LogicValueType/BooleanType/
We're moving toward using that protocol for straight-up Bool types

Swift SVN r19884
2014-07-12 18:58:18 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Jordan Rose
44b93b5ebc [XCTest] Fix enumerator names after r19732.
Swift SVN r19736
2014-07-09 19:48:34 +00:00
Chris Hanson
73d268f0a9 XCTest: Use the new convention for format strings
When asking XCTest to generate format strings for assertions, pass the
requested index + 100 to ask XCTest to generate a string without space
for the expressions themselves, and don't bother passing them either
(since the overlay isn't actually generating stringified expressons).

Addresses <rdar://problem/17597526>.

Swift SVN r19712
2014-07-08 23:27:34 +00:00
Doug Gregor
0c31ff5681 Move bridging conversions into the type checker.
Previously, bridged value types and their corresponding Objective-C
classes allow inter-conversion via a number of user-defined conversion
functions in the Foundation module. Instead, make this a general
feature of the type checker so we can reason about it more
directly. Fixes <rdar://problem/16956098> and
<rdar://problem/17134986>, and eliminates 11 (half) of the
__conversion functions from the standard library and overlays.

A few notes:
  - The XCTest changes are because a String can no longer directly
  conform to CVarArg: this is a Good Thing (TM), because it should be
  ambiguous: did you mean to pass it as an NSString or a C string?
  - The Objective-C representations for the bridged collections are
  hard-coded in the type checker. This is unfortunate and can be
  remedied by adding another associated type to the
  _BridgedToObjectiveC protocol.

Swift SVN r19618
2014-07-07 18:04:18 +00:00
Anna Zaks
6aadb1a647 APIs in XCTest now uses UInt, not Int.
Fixup for r19536.

Swift SVN r19538
2014-07-03 22:33:07 +00:00
Chris Hanson
d459ee4a3d Since all NSObject subclasses are Equatable, we can just use XCTAssertEqual/XCTAssertNotEqual.
Addresses <rdar://problem/17257148>

Swift SVN r19496
2014-07-03 00:31:08 +00:00
Chris Hanson
5b9b67e900 Revert "Remove XCTest overlay"
We need to actually keep the XCTest support in an overlay for now.

This reverts commit 4a2726862634a553483943baf39a251ac8071e37.

Addresses <rdar://problem/17423669>.

Swift SVN r19101
2014-06-23 21:00:47 +00:00
Chris Hanson
7d1cf3d107 Remove XCTest overlay
The XCTest support for Swift is now built as part of XCTest.framework
itself, so the overlay is no longer necessary.

Addresses <rdar://problem/17383462>.

Swift SVN r19016
2014-06-19 22:08:52 +00:00
Joe Pamer
1d34a88477 Revert "Fix two problems with implicit conversions: - rdar://problem/16776273, wherein conversions between nil and .None were permitted due to an implicit conversion between nil and COpaquePointer. - rdar://problem/16877526, where we needed to add new equality overloads to handle conversions between nil and .None given the supression of user conversions. (Thanks to Ted for the overloads and test.)"
This reverts commit r18473.

Swift SVN r18477
2014-05-21 00:28:46 +00:00
Joe Pamer
f469d8f1f6 Fix two problems with implicit conversions:
- rdar://problem/16776273, wherein conversions between nil and .None were permitted
due to an implicit conversion between nil and COpaquePointer.
- rdar://problem/16877526, where we needed to add new equality overloads to handle
conversions between nil and .None given the supression of user conversions.
(Thanks to Ted for the overloads and test.)

Swift SVN r18473
2014-05-20 23:53:34 +00:00
Ted Kremenek
92157d7d55 Change 'isSignMinus', 'isNormal', etc., in FloatingPointNumber to properties.
Swift SVN r18306
2014-05-18 04:20:09 +00:00
Arnold Schwaighofer
da6d9152b6 Differentiate between user assertion and preconditions and the like
assert() and fatalError()
These functions are meant to be used in user code. They are enabled in debug
mode and disabled in release or fast mode.

_precondition() and _preconditionFailure()
These functions are meant to be used in library code to check preconditions at
the api boundry. They are enabled in debug mode (with a verbose message) and
release mode (trap). In fast mode they are disabled.

_debugPrecondition() and _debugPreconditionFailure()
These functions are meant to be used in library code to check preconditions that
are not neccesarily comprehensive for safety (UnsafePointer can be null or an
invalid pointer but we can't check both). They are enabled only in debug mode.

_sanityCheck() and _fatalError()
These are meant to be used for internal consistency checks. They are only
enabled when the library is build with -DSWIFT_STDLIB_INTERNAL_CHECKS=ON.

I modified the code in the standard library to the best of my judgement.

rdar://16477198

Swift SVN r18212
2014-05-16 20:49:54 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Chris Hanson
190c5c8477 Implement an XCTest overlay with basic assertions
Adds an overlay for Xcode's XCTest testing framework.

It implements most of the familiar test assertion macros as equivalent
Swift functions. The assertion macros that aren't currently implemented
are only those that deal specifically with floating-point equality and
Objective-C exceptions. Additionally, the implemented assertions don't
currently handle Objective-C exceptions thrown out of some code called
during an assertion as test failures.

Swift SVN r15917
2014-04-04 01:55:08 +00:00