Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,6 @@ getAlternativeLiteralTypes(KnownProtocolKind kind) {

SmallVector<Type, 4> types;

// If the default literal type is bridged to a class type, add the class type.
if (auto proto = TC.Context.getProtocol(kind)) {
if (auto defaultType = TC.getDefaultType(proto, DC)) {
if (auto bridgedClassType = TC.getBridgedToObjC(DC, defaultType)) {
types.push_back(bridgedClassType);
}
}
}

// Some literal kinds are related.
switch (kind) {
#define PROTOCOL_WITH_NAME(Id, Name) \
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/SDK/XCTest/XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ func _XCTRunThrowableBlock(_ block: @noescape () throws -> Void) -> _XCTThrowabl
if let blockError = blockErrorOptional {
return .failedWithError(error: blockError)
} else if d.count > 0 {
let t: String = d["type"] as! String
let t: String = d["type" as NSString] as! String

if t == "objc" {
return .failedWithException(
className: d["className"] as! String,
name: d["name"] as! String,
reason: d["reason"] as! String)
className: d["className" as NSString] as! String,
name: d["name" as NSString] as! String,
reason: d["reason" as NSString] as! String)
} else {
return .failedWithUnknownException
}
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/ArrayTrapsObjC.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ArrayTraps.test("downcast2")
{ _isFastAssertConfiguration() },
reason: "this trap is not guaranteed to happen in -Ounchecked"))
.code {
let a: [AnyObject] = ["String", 1]
let a: [AnyObject] = ["String" as NSString, 1 as NSNumber]
let sa = a as! [NSString]
let s0 = sa[0]
expectCrashLater()
Expand Down
4 changes: 2 additions & 2 deletions test/1_stdlib/DictionaryLiteral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ let anNSString = "Foo" as NSString
var stringNSStringLet: DictionaryLiteral = [ "a": aString as NSString, "b": anNSString]
expectType(DictionaryLiteral<String, NSString>.self, &stringNSStringLet)

var hetero1: DictionaryLiteral = ["a": 1, "b": "Foo" as NSString]
var hetero1: DictionaryLiteral = ["a": 1 as NSNumber, "b": "Foo" as NSString]
expectType(DictionaryLiteral<String, NSObject>.self, &hetero1)

var hetero2: DictionaryLiteral = ["a": 1, "b": "Foo"]
var hetero2: DictionaryLiteral = ["a": 1 as NSNumber, "b": "Foo" as NSString]
expectType(DictionaryLiteral<String, NSObject>.self, &hetero2)
8 changes: 4 additions & 4 deletions test/1_stdlib/NSArrayAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ var NSArrayAPI = TestSuite("NSArrayAPI")

NSArrayAPI.test("mixed types with AnyObject") {
do {
let result: AnyObject = [1, "two"]
let expect: NSArray = [1, "two"]
let result: AnyObject = [1 as NSNumber, "two" as NSString] as NSArray
let expect: NSArray = [1 as NSNumber, "two" as NSString]
expectEqual(expect, result as! NSArray)
}
do {
let result: AnyObject = [1, 2]
let expect: NSArray = [1, 2]
let result: AnyObject = [1 as NSNumber, 2 as NSNumber] as NSArray
let expect: NSArray = [1 as NSNumber, 2 as NSNumber]
expectEqual(expect, result as! NSArray)
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/1_stdlib/NSObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ let o1 = NSObject.init()
let o2 = NSObject.init()
printIdentity(o1, o2, "o1", "o2")
printEquality(o1, o2, "o1", "o2")
printIdentity(o1, 10, "o1", "10")
printEquality(o1, 10, "o1", "10")
printIdentity(10, o1, "10", "o1")
printEquality(10, o1, "10", "o1")
printIdentity(o1, 10 as NSNumber, "o1", "10")
printEquality(o1, 10 as NSNumber, "o1", "10")
printIdentity(10 as NSNumber, o1, "10", "o1")
printEquality(10 as NSNumber, o1, "10", "o1")
print("done NSObject ==")
// CHECK: NSObject ==
// CHECK-NEXT: o1 === o1
Expand Down
39 changes: 0 additions & 39 deletions test/1_stdlib/NSStringAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,6 @@ NSStringAPIs.test("init(format:locale:arguments:)") {
locale: nil, arguments: args))
}

NSStringAPIs.test("lastPathComponent") {
expectEqual("bar", "/foo/bar".lastPathComponent)
expectEqual("абв", "/foo/абв".lastPathComponent)
}

NSStringAPIs.test("utf16Count") {
expectEqual(1, "a".utf16.count)
expectEqual(2, "\u{0001F60A}".utf16.count)
Expand Down Expand Up @@ -1035,11 +1030,6 @@ NSStringAPIs.test("pathComponents") {
expectEqual([ "/", "абв", "где" ] as [NSString], ("/абв/где" as NSString).pathComponents as [NSString])
}

NSStringAPIs.test("pathExtension") {
expectEqual("", "/foo/bar".pathExtension)
expectEqual("txt", "/foo/bar.txt".pathExtension)
}

NSStringAPIs.test("precomposedStringWithCanonicalMapping") {
expectEqual("abc", "abc".precomposedStringWithCanonicalMapping)
expectEqual("だくてん",
Expand Down Expand Up @@ -1359,26 +1349,13 @@ NSStringAPIs.test("appendingFormat(_:_:...)") {
.appendingFormat("def %@ %ld", formatArg, 42))
}

NSStringAPIs.test("appendingPathComponent(_:)") {
expectEqual("", "".appendingPathComponent(""))
expectEqual("a.txt", "".appendingPathComponent("a.txt"))
expectEqual("/tmp/a.txt", "/tmp".appendingPathComponent("a.txt"))
}

NSStringAPIs.test("appending(_:)") {
expectEqual("", "".appending(""))
expectEqual("a", "a".appending(""))
expectEqual("a", "".appending("a"))
expectEqual("さ\u{3099}", "さ".appending("\u{3099}"))
}

NSStringAPIs.test("deletingLastPathComponent") {
expectEqual("", "".deletingLastPathComponent)
expectEqual("/", "/".deletingLastPathComponent)
expectEqual("/", "/tmp".deletingLastPathComponent)
expectEqual("/tmp", "/tmp/a.txt".deletingLastPathComponent)
}

NSStringAPIs.test("folding(options:locale:)") {

func fwo(
Expand Down Expand Up @@ -1597,22 +1574,6 @@ NSStringAPIs.test("replacingPercentEscapes(using:)/rdar18029471")
using: .ascii))
}

NSStringAPIs.test("resolvingSymlinksInPath") {
// <rdar://problem/18030188> Difference between
// resolvingSymlinksInPath and stringByStandardizingPath is unclear
expectEqual("", "".resolvingSymlinksInPath)
expectEqual(
"/var", "/private/var/tmp////..//".resolvingSymlinksInPath)
}

NSStringAPIs.test("standardizingPath") {
// <rdar://problem/18030188> Difference between
// resolvingSymlinksInPath and standardizingPath is unclear
expectEqual("", "".standardizingPath)
expectEqual(
"/var", "/private/var/tmp////..//".standardizingPath)
}

NSStringAPIs.test("trimmingCharacters(in:)") {
expectEqual("", "".trimmingCharacters(
in: CharacterSet.decimalDigits))
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/RuntimeObjC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ Reflection.test("Unmanaged/nil") {
Reflection.test("Unmanaged/not-nil") {
var output = ""
var optionalURL: Unmanaged<CFURL>? =
Unmanaged.passRetained(CFURLCreateWithString(nil, "http://llvm.org/", nil))
Unmanaged.passRetained(CFURLCreateWithString(nil, "http://llvm.org/" as CFString, nil))
dump(optionalURL, to: &output)

let expected =
Expand Down
2 changes: 1 addition & 1 deletion test/Interpreter/SDK/Foundation_NSExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

// Test overlain variadic methods.
let expression = NSExpression(format: "(3 + 2)**2", "LLLL", "BBBB")
let expression = NSExpression(format: "(3 + 2)**2", "LLLL" as NSString, "BBBB" as NSString)
let result = expression.expressionValue(with: expression, context:nil) as! NSNumber
let number = result.stringValue
print(number)
Expand Down
2 changes: 1 addition & 1 deletion test/Interpreter/SDK/Foundation_NSLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ testNSLog()
// CHECK: 1 is the loneliest number that you'll ever do
NSLog(
"%@ is the loneliest number that you'll ever %@",
NSNumber(value: 1), "do"
NSNumber(value: 1), "do" as NSString
)
2 changes: 1 addition & 1 deletion test/Interpreter/SDK/Foundation_NSPredicate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Foundation

// Test overlain variadic methods.
let s = NSPredicate(format: "(lastName like[cd] %@) AND (birthday > %@)", "LLLL", "BBBB")
let s = NSPredicate(format: "(lastName like[cd] %@) AND (birthday > %@)", "LLLL" as NSString, "BBBB" as NSString)
print(s.predicateFormat)

// CHECK: lastName LIKE[cd] "LLLL" AND birthday > "BBBB"
8 changes: 4 additions & 4 deletions test/Interpreter/SDK/Foundation_NSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,21 @@ testComparisons()
// CHECK-LABEL: Variadic methods:
print("Variadic methods:")
// CHECK-NEXT: x y
print(NSString(format: "%@ %@", "x", "y"))
print(NSString(format: "%@ %@", "x" as NSString, "y" as NSString))
// CHECK-NEXT: 1{{.*}}024,25
print(NSString(
format: "%g",
locale: Locale(identifier: "fr_FR"),
1024.25
))
// CHECK-NEXT: x y z
print(("x " as NSString).appendingFormat("%@ %@", "y", "z"))
print(("x " as NSString).appendingFormat("%@ %@", "y" as NSString, "z" as NSString))
// CHECK-NEXT: a b c
let s = NSMutableString(string: "a ")
s.appendFormat("%@ %@", "b", "c")
s.appendFormat("%@ %@", "b" as NSString, "c" as NSString)
print(s)

let m = NSMutableString.localizedStringWithFormat("<%@ %@>", "q", "r")
let m = NSMutableString.localizedStringWithFormat("<%@ %@>", "q" as NSString, "r" as NSString)
// CHECK-NEXT: <q r>
print(m)
m.append(" lever")
Expand Down
20 changes: 10 additions & 10 deletions test/Interpreter/SDK/Foundation_test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ FoundationTestSuite.test("arrayConversions") {
//===----------------------------------------------------------------------===//

FoundationTestSuite.test("NSDictionary") {
var nsDict : NSDictionary = [1 : "Hello", 2 : "World"]
assert((nsDict[1]! as! NSString).isEqual("Hello"))
assert((nsDict[2]! as! NSString).isEqual("World"))
var nsDict : NSDictionary = [1 as NSNumber : "Hello" as NSString, 2 as NSNumber : "World" as NSString]
assert((nsDict[1 as NSNumber]! as! NSString).isEqual("Hello"))
assert((nsDict[2 as NSNumber]! as! NSString).isEqual("World"))

let nsMutableDict: NSMutableDictionary = ["Hello" : 1, "World" : 2]
assert((nsMutableDict["Hello"]! as AnyObject).isEqual(1))
assert((nsMutableDict["World"]! as AnyObject).isEqual(2))
let nsMutableDict: NSMutableDictionary = ["Hello" as NSString : 1 as NSNumber, "World" as NSString : 2 as NSNumber]
assert((nsMutableDict["Hello" as NSString]! as AnyObject).isEqual(1))
assert((nsMutableDict["World" as NSString]! as AnyObject).isEqual(2))
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -189,9 +189,9 @@ class ClassWithDtor : NSObject {
FoundationTestSuite.test("rdar://17584531") {
// <rdar://problem/17584531>
// Type checker used to be confused by this.
var dict: NSDictionary = ["status": 200, "people": [["id": 255, "name": ["first": "John", "last": "Appleseed"]]]]
var dict2 = dict["people"].map { $0 as AnyObject }?[0] as! NSDictionary
expectEqual("Optional(255)", String(describing: dict2["id"]))
var dict: NSDictionary = ["status" as NSString: 200 as NSNumber, "people" as NSString: [["id" as NSString: 255 as NSNumber, "name" as NSString: ["first" as NSString: "John" as NSString, "last" as NSString: "Appleseed" as NSString] as NSDictionary] as NSDictionary] as NSArray] as NSDictionary
var dict2 = dict["people" as NSString].map { $0 as AnyObject }?[0] as! NSDictionary
expectEqual("Optional(255)", String(describing: dict2["id" as NSString]))
}

FoundationTestSuite.test("DarwinBoolean smoke test") {
Expand Down Expand Up @@ -384,7 +384,7 @@ if #available(OSX 10.11, iOS 9.0, *) {
}

FoundationTestSuite.test("NotificationCenter/addObserver(_:selector:name:object:)") {
let obj: AnyObject = "Hello"
let obj: AnyObject = "Hello" as NSString
NotificationCenter.default.addObserver(obj, selector: Selector("blah:"),
name: nil, object: nil)
let name = "hello"
Expand Down
30 changes: 15 additions & 15 deletions test/Interpreter/SDK/dictionary_pattern_matching.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct State {
let abbrev: String
}

func stateFromPlistLame(_ plist: Dictionary<String, AnyObject>) -> State? {
func stateFromPlistLame(_ plist: Dictionary<String, Any>) -> State? {
if let name = plist["name"] as? NSString {
if let population = plist["population"] as? NSNumber {
if let abbrev = plist["abbrev"] as? NSString {
Expand All @@ -26,7 +26,7 @@ func stateFromPlistLame(_ plist: Dictionary<String, AnyObject>) -> State? {
return nil
}

func stateFromPlistCool(_ plist: Dictionary<String, AnyObject>) -> State? {
func stateFromPlistCool(_ plist: Dictionary<String, Any>) -> State? {
switch (plist["name"], plist["population"], plist["abbrev"]) {
case let (name as String, pop as Int, abbr as String)
where abbr.characters.count == 2:
Expand All @@ -38,22 +38,22 @@ func stateFromPlistCool(_ plist: Dictionary<String, AnyObject>) -> State? {
}
}

let goodStatePlist: Dictionary<String, AnyObject> = [
"name": "California",
"population": 38_040_000,
"abbrev": "CA",
let goodStatePlist: Dictionary<String, Any> = [
"name" as String: "California",
"population" as String: 38_040_000,
"abbrev" as String: "CA",
]
let invalidStatePlist1: Dictionary<String, AnyObject> = [
let invalidStatePlist1: Dictionary<String, Any> = [
"name": "California",
"population": "hella",
"abbrev": "CA",
]
let invalidStatePlist2: Dictionary<String, AnyObject> = [
let invalidStatePlist2: Dictionary<String, Any> = [
"name": "California",
"population": 38_040_000,
"abbrev": "Cali",
]
let invalidStatePlist3: Dictionary<String, AnyObject> = [
let invalidStatePlist3: Dictionary<String, Any> = [
"name": "California",
"population": 38_040_000,
]
Expand Down Expand Up @@ -102,7 +102,7 @@ enum Statistic : CustomReflectable {
}
}

func statisticFromPlist(_ plist: Dictionary<String, AnyObject>) -> Statistic? {
func statisticFromPlist(_ plist: Dictionary<String, Any>) -> Statistic? {
switch (plist["kind"], plist["name"], plist["population"], plist["abbrev"]) {
case let ("state" as String, name as String, population as Int, abbrev as String)
where abbrev.characters.count == 2:
Expand All @@ -117,29 +117,29 @@ func statisticFromPlist(_ plist: Dictionary<String, AnyObject>) -> Statistic? {
}
}

let goodStatePlist2: Dictionary<String, AnyObject> = [
let goodStatePlist2: Dictionary<String, Any> = [
"kind": "state",
"name": "California",
"population": 38_040_000,
"abbrev": "CA"
]
let goodCountryPlist: Dictionary<String, AnyObject> = [
let goodCountryPlist: Dictionary<String, Any> = [
"kind": "country",
"name": "India",
"population": 1_23_70_00_000,
]
let invalidCountryPlist1: Dictionary<String, AnyObject> = [
let invalidCountryPlist1: Dictionary<String, Any> = [
"kind": "country",
"name": "India",
"population": 1_23_70_00_000,
"abbrev": "IN"
]
let invalidCountryPlist2: Dictionary<String, AnyObject> = [
let invalidCountryPlist2: Dictionary<String, Any> = [
"kind": "country",
"name": "India",
"population": "123 crore",
]
let invalidKindPlist: Dictionary<String, AnyObject> = [
let invalidKindPlist: Dictionary<String, Any> = [
"kind": "planet",
"name": "Mercury",
"population": 0
Expand Down
3 changes: 3 additions & 0 deletions test/Interpreter/SDK/objc_cast.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// RUN: %target-run-simple-swift | FileCheck %s
// REQUIRES: executable_test

// rdar://problem/27616753
// XFAIL: *

// REQUIRES: objc_interop

import Foundation
Expand Down
8 changes: 4 additions & 4 deletions test/Interpreter/SDK/objc_dynamic_lookup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import Foundation

// Dynamic subscripting of NSArray, dynamic method dispatch
// CHECK: {{^3$}}
var array : AnyObject = [1, 2, 3, 4, 5]
var array : AnyObject = [1 as NSNumber, 2 as NSNumber, 3 as NSNumber, 4 as NSNumber, 5 as NSNumber] as NSArray
print((array[2] as AnyObject).description)

// Dynamic subscripting on an array using an object (fails)
// CHECK: NSArray subscript with an object fails
var optVal1 = array["Hello"]
var optVal1 = array["Hello" as NSString]
if optVal1 != nil {
print(((optVal1!)! as AnyObject).description)
} else {
Expand All @@ -21,9 +21,9 @@ if optVal1 != nil {

// Dynamic subscripting of NSDictionary, dynamic method dispatch
// CHECK: {{^2$}}
var nsdict : NSDictionary = ["Hello" : 1, "World" : 2]
var nsdict : NSDictionary = ["Hello" as NSString : 1 as NSNumber, "World" as NSString : 2 as NSNumber]
var dict : AnyObject = nsdict
print(((dict["World"]!)! as AnyObject).description)
print(((dict["World" as NSString]!)! as AnyObject).description)

// Dynamic subscripting on a dictionary using an index (fails)
// CHECK: NSDictionary subscript with an index fails
Expand Down
Loading