Commit Graph

43 Commits

Author SHA1 Message Date
Erik Eckstein
9e7e6865dd tests: re-enable Interpreter/SDK/objc_cast.swift
Needed to add some explicit casts to NSObject

rdar://33021520
2021-02-25 10:32:35 +01:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Joe Groff
c748ba6c12 Merge pull request #3870 from jckarter/no-bridged-default-literal-types
Sema: Don't try bridged classes as default literal types.
2016-07-29 22:16:53 -07:00
Joe Groff
11f03cd8b5 Sema: Don't try bridged classes as default literal types.
One last bit of SE-0072. We shouldn't fall back to bridged classes in the absence of type context for literals anymore. By itself, this kind of hoses the use of literals with NS types, but I think we can get most of the QoI back with overlay changes I plan to propose following this.
2016-07-29 15:18:31 -07:00
Rintaro Ishizaki
c6f4bcd01e [SE-0101] MemoryLayout: Migrate testsuite and benchmarks 2016-07-30 03:11:45 +09:00
Mishal Shah
87b7bcfd3e Update master to build with Xcode 8 beta 1, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-06-14 14:53:55 -07:00
Chris Willmore
af0c7bd620 Initial implementation of SE-0054 "Abolish IUO Type" (#2322)
This is a squash of the following commits:

* [SE-0054] Import function pointer arg, return types, typedefs as optional

IUOs are only allowed on function decl arguments and return types, so
don't import typedefs or function pointer args or return types as IUO.

* [SE-0054] Only allow IUOs in function arg and result type.

When validating a TypeRepr, raise a diagnostic if an IUO is found
anywhere other thn the top level or as a function parameter or return
tpye.

* [SE-0054] Disable inference of IUOs by default

When considering a constraint of the form '$T1 is convertible to T!',
generate potential bindings 'T' and 'T?' for $T1, but not 'T!'. This
prevents variables without explicit type information from ending up with
IUO type. It also prevents implicit instantiation of functions and types
with IUO type arguments.

* [SE-0054] Remove the -disable-infer-iuos flag.

* Add nonnull annotations to ObjectiveCTests.h in benchmark suite.
2016-05-03 14:06:19 -07:00
Chris Willmore
73d5077bae Add API notes for Foundation following internal Swift 3 naming audit. 2016-04-07 20:35:18 -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
Dmitri Gribenko
65d840c0ae stdlib: lowercase cases in Optional and ImplicitlyUnwrappedOptional 2016-02-18 00:40:33 -08:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
Wojtek Czekalski
63f36a8931 Fixed tests of printing of floats after behavior change
debugDescription of all floating point numbers shows the number with greater precision, thus the tests had to be changed.
2015-12-14 19:25:14 +01:00
Jordan Rose
50c0cf5319 [IRGen] Casts to an ObjC-class-bound archetype are not casts to the bound.
And they're not even guaranteed to be casts to ObjC classes. They might be
Swift subclasses of ObjC classes.

This fixes a type-safety hole where, e.g. a generic cast from NSPredicate
to NSDate was allowed because we were checking against NSObject.

rdar://problem/22242369

Swift SVN r31153
2015-08-12 01:07:31 +00:00
David Farler
9aa7663ad3 Always debugPrint containers' elements
rdar://problem/19312992

Swift SVN r31067
2015-08-07 06:14:19 +00:00
Arnold Schwaighofer
859fbc0162 More executable_test for the test directory
Swift SVN r29280
2015-06-03 23:28:51 +00:00
Dmitri Hrybenko
f46f16ae82 stdlib: implement new print() API
rdar://20775683

Swift SVN r28309
2015-05-08 01:37:59 +00:00
Graham Batty
83b4384fac Update test flags for linux failures and support.
Also removed the sdk 'feature' in favour of the more specific
objc_interop.

Swift SVN r24856
2015-01-30 21:31:48 +00:00
Chris Willmore
68dd563fbf <rdar://problem/18311362> TLF: Eliminate implicit bridging conversions
Require 'as' when converting from Objective-C type to native type (but
continue to allow implicit conversion from native to Objective-C). This
conversion constraint is called ExplicitConversion; all implicit
conversions are covered by the existing Conversion constraint. Update
standard library and tests to match.

Swift SVN r24496
2015-01-18 00:07:45 +00:00
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
Graham Batty
83f27a8af7 Revert "Mark tests that don't pass on linux as XFAIL."
This reverts commit 2711ca86de7bf6a7885ccea24219a48a590b1e95.

Swift SVN r23577
2014-11-24 17:42:13 +00:00
Graham Batty
198402dcfe Mark tests that don't pass on linux as XFAIL.
Swift SVN r23573
2014-11-24 17:40:37 +00:00
Joe Pamer
94dac129d4 Remove the BooleanType conformance from optional types (rdar://problem/17110911)
To limit user confusion when using conditional expressions of type Bool?, we've decided to remove the BooleanType (aka "LogicValue") conformance from optional types. (If users would like to use an expression of type Bool? as a conditional, they'll need to check against nil.)

Note: This change effectively regresses the "case is" pattern over types, since it currently demands a BooleanType conformance. I've filed rdar://problem/17791533 to track reinstating it if necessary.

Swift SVN r20637
2014-07-28 19:20:39 +00:00
Doug Gregor
a5c079af59 Replace the class_protocol attribute with a "class" requirement.
This only tackles the protocol case (<rdar://problem/17510790>); it
does not yet generalize to an arbitrary "class" requirement on either
existentials or generics.

Swift SVN r19896
2014-07-13 06:57:48 +00:00
Doug Gregor
e6227bcc54 Remove XFAILs for 32-bit targets. This was part of <rdar://problem/17411843>
Swift SVN r19488
2014-07-02 23:13:50 +00:00
Doug Gregor
9210cd5ff4 Replace T[] array syntax with [T] in the test suite
Swift SVN r19192
2014-06-25 23:39:24 +00:00
Greg Parker
11f99d8b31 [test] Disable test objc_cast.swift on 32-bit pending rdar://17411843.
Swift SVN r19081
2014-06-22 19:27:53 +00:00
Doug Gregor
c094309d70 Add a runtime test for a failed conditional, bridged binding.
Swift SVN r19066
2014-06-21 13:32:00 +00:00
Doug Gregor
37e242cc90 Rework handling of optionals for bridging forced and conditional downcasts.
Previously, we were unable to handle bridged downcasts to optional
types from optional sources, because because we applied the bridging
operation after we had already evaluated all of the bound optionals
(causing a crash). Now, we perform the bridging immediately after the
underlying forced or conditional cast, before evaluating the outer
bound optionals.

This also eliminates a bunch of code duplication between the forced
and conditional downcasts, now that the bridging code is shared.



Swift SVN r19065
2014-06-21 13:30:50 +00:00
Doug Gregor
fd62de4373 Use bridgeFromObjectiveCConditional where we want conditional bridging.
More of <rdar://problem/17319154>.


Swift SVN r19038
2014-06-20 07:41:50 +00:00
Doug Gregor
2e3863b211 Introduce _ConditionallyBridgedToObjectiveC.bridgeFromObjectiveCConditional.
This entry point is used in conditional downcasts (as?) to attempt to
bridge from an Objective-C class down to a specific native type (e.g.,
array, dictionary), bridging all elements eagerly so that it can
produce nil if the bridging would fail.

This is the scaffolding for <rdar://problem/17319154>, and makes the
example there work, but there is much more cleanup and optimization to
do.



Swift SVN r18999
2014-06-19 14:48:00 +00:00
Doug Gregor
08be461122 When performing an "is" check that involves bridging, do a full conditional check.
Previously, we were only changing whether the object was of the right
type, and not performing a deep check that (for example) the
underlying array contained NSStrings for an "is String[]". Fixes the
rest of <rdar://problem/16972956>.


Swift SVN r18728
2014-06-06 04:22:45 +00:00
Doug Gregor
fb93d14aec Generalize downcasting through an Objective-C class to a bridged value type.
Rather than only allowing downcasting from AnyObject, allow it for any
class or Objective-C existential type, e.g., "NSArray() as
Int[]". While here, reduce our reliance on implicit conversions when
checking bridging. This is most of <rdar://problem/16972956>, but 'is'
still doesn't work properly in these cases.


Swift SVN r18693
2014-06-02 15:44:48 +00:00
Doug Gregor
67ca1c9ea1 Implement the new casting syntaxes "as" and "as?".
There's a bit of a reshuffle of the ExplicitCastExpr subclasses:
  - The existing ConditionalCheckedCastExpr expression node now represents
"as?". 
  - A new ForcedCheckedCastExpr node represents "as" when it is a
  downcast.
  - CoerceExpr represents "as" when it is a coercion.
  - A new UnresolvedCheckedCastExpr node describes "as" before it has
  been type-checked down to ForcedCheckedCastExpr or CoerceExpr. This
  wasn't a strictly necessary change, but it helps us detangle what's
  going on.

There are a few new diagnostics to help users avoid getting bitten by
as/as? mistakes:
  - Custom errors when a forced downcast (as) is used as the operand
  of postfix '!' or '?', with Fix-Its to remove the '!' or make the
  downcast conditional (with as?), respectively.
  - A warning when a forced downcast is injected into an optional,
  with a suggestion to use a conditional downcast.
  - A new error when the postfix '!' is used for a contextual
  downcast, with a Fix-It to replace it with "as T" with the
  contextual type T.

Lots of test updates, none of which felt like regressions. The new
tests are in test/expr/cast/optionals.swift. 

Addresses <rdar://problem/17000058>


Swift SVN r18556
2014-05-22 06:15:29 +00:00
Doug Gregor
1cb05e5b0b When force-casting AnyObject to a contextual type, bridge through Objective-C.
Previously, we were relying on user-defined conversions to perform the
final bridging from the Objective-C class type (e.g., NSString) to its
Swift value type (String). That works for NSString <-> String, but not
for arbitrary arrays. Use the bridgeFromObjectiveC() witness instead,
so we can handle:

  let obj: AnyObject = ...
  let strArr: String[] = obj!

Fixes <rdar://problem/16952771>.

Swift SVN r18422
2014-05-19 15:32:06 +00:00
Doug Gregor
57f75b7448 Implement bridging from NSNumber to Int/UInt/Float/Double/Bool.
This makes fun bridging like

  var obj: AnyObject! = [3.14159, 2.71828, 0] as Double[]
  if let intArr = obj as Int[] {
    println("Array of doubles as ints is \(intArr)")
  }

"work", given that NSNumber is the common class type through which we
are bridging.




Swift SVN r18398
2014-05-19 07:33:15 +00:00
Doug Gregor
10380943d4 Support checked downcasting through a class type to a non-verbatim bridged value type.
This allows us to cast an AnyObject (or optional thereof) down to a
specific array, e.g.,

  if let strArr = obj as String[] { ... }

Addresses most of <rdar://problem/16952771>.



Swift SVN r18397
2014-05-19 07:15:30 +00:00
Doug Gregor
9c8f571d96 Teach "is" expressions to cope with optionals.
The "is" expression itself isn't really able to cope with optionals
well itself, so in the hard cases we'll defer to a conditional checked
cast and then check whether the resulting optional is non-empty. Fixes
the rest of <rdar://problem/16953860>.

Swift SVN r18361
2014-05-18 22:05:20 +00:00
Doug Gregor
2df46e4733 Don't unwrap implicitly unwrapped optionals before casting.
Checked casting handles multiple levels of optionality properly
already, and does so by binding rather than forcing. Fixes the
immediate issue in <rdar://problem/16953860>.

Swift SVN r18351
2014-05-18 21:03:56 +00:00
Doug Gregor
e7ad745be0 Support downcasting from AnyObject to a bridged value type.
This allows us to cast "through" a bridged class type in an "as" case,
e.g.,

  if let str = obj as String { ... }

where obj is an AnyObject (or optional/implicitly unwrapped optional
thereof). In such cases, we perform a checked cast to the
corresponding class type (NSString in this case) and then convert the
(optional!) result down to the value type.

Addresses the main part of <rdar://problem/15288553>, but we still
have trouble with "is" with optionals, and the #if false'd out
testcase incorrectly fails due to <rdar://problem/16953860>.

Swift SVN r18347
2014-05-18 20:30:39 +00:00
Joe Pamer
a74c44a6e4 Fix two crashing bugs related to checked downcasts - rdar://problem/16093456 and rdar://problem/16892211.
Swift SVN r18118
2014-05-15 18:36:44 +00:00
Doug Gregor
d5a9c2ab94 Only supersede initializers with other imported initializers when the types match.
This fixes a case where the Swift-variadic and C-varargs versions of
various initializers were superseding each other
<rdar://problem/16801456>.

It also uncovered some more cases where we weren't getting quite the
right semantics for factory-methods-as-initializers, which are also
fixed here.

Swift SVN r18010
2014-05-13 16:49:39 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Greg Parker
ec31b01246 Remove incorrect optimization of dynamic casts of non-ObjC objects.
Swift SVN r8907
2013-10-04 04:17:26 +00:00