Skip to content

Commit c748ba6

Browse files
authored
Merge pull request #3870 from jckarter/no-bridged-default-literal-types
Sema: Don't try bridged classes as default literal types.
2 parents 5a2406b + 11f03cd commit c748ba6

27 files changed

+83
-125
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,6 @@ getAlternativeLiteralTypes(KnownProtocolKind kind) {
256256

257257
SmallVector<Type, 4> types;
258258

259-
// If the default literal type is bridged to a class type, add the class type.
260-
if (auto proto = TC.Context.getProtocol(kind)) {
261-
if (auto defaultType = TC.getDefaultType(proto, DC)) {
262-
if (auto bridgedClassType = TC.getBridgedToObjC(DC, defaultType)) {
263-
types.push_back(bridgedClassType);
264-
}
265-
}
266-
}
267-
268259
// Some literal kinds are related.
269260
switch (kind) {
270261
#define PROTOCOL_WITH_NAME(Id, Name) \

stdlib/public/SDK/XCTest/XCTest.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ func _XCTRunThrowableBlock(_ block: @noescape () throws -> Void) -> _XCTThrowabl
7070
if let blockError = blockErrorOptional {
7171
return .failedWithError(error: blockError)
7272
} else if d.count > 0 {
73-
let t: String = d["type"] as! String
73+
let t: String = d["type" as NSString] as! String
7474

7575
if t == "objc" {
7676
return .failedWithException(
77-
className: d["className"] as! String,
78-
name: d["name"] as! String,
79-
reason: d["reason"] as! String)
77+
className: d["className" as NSString] as! String,
78+
name: d["name" as NSString] as! String,
79+
reason: d["reason" as NSString] as! String)
8080
} else {
8181
return .failedWithUnknownException
8282
}

test/1_stdlib/ArrayTrapsObjC.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ArrayTraps.test("downcast2")
3737
{ _isFastAssertConfiguration() },
3838
reason: "this trap is not guaranteed to happen in -Ounchecked"))
3939
.code {
40-
let a: [AnyObject] = ["String", 1]
40+
let a: [AnyObject] = ["String" as NSString, 1 as NSNumber]
4141
let sa = a as! [NSString]
4242
let s0 = sa[0]
4343
expectCrashLater()

test/1_stdlib/DictionaryLiteral.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ let anNSString = "Foo" as NSString
5151
var stringNSStringLet: DictionaryLiteral = [ "a": aString as NSString, "b": anNSString]
5252
expectType(DictionaryLiteral<String, NSString>.self, &stringNSStringLet)
5353

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

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

test/1_stdlib/NSArrayAPI.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ var NSArrayAPI = TestSuite("NSArrayAPI")
1212

1313
NSArrayAPI.test("mixed types with AnyObject") {
1414
do {
15-
let result: AnyObject = [1, "two"]
16-
let expect: NSArray = [1, "two"]
15+
let result: AnyObject = [1 as NSNumber, "two" as NSString] as NSArray
16+
let expect: NSArray = [1 as NSNumber, "two" as NSString]
1717
expectEqual(expect, result as! NSArray)
1818
}
1919
do {
20-
let result: AnyObject = [1, 2]
21-
let expect: NSArray = [1, 2]
20+
let result: AnyObject = [1 as NSNumber, 2 as NSNumber] as NSArray
21+
let expect: NSArray = [1 as NSNumber, 2 as NSNumber]
2222
expectEqual(expect, result as! NSArray)
2323
}
2424
}

test/1_stdlib/NSObject.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ let o1 = NSObject.init()
7171
let o2 = NSObject.init()
7272
printIdentity(o1, o2, "o1", "o2")
7373
printEquality(o1, o2, "o1", "o2")
74-
printIdentity(o1, 10, "o1", "10")
75-
printEquality(o1, 10, "o1", "10")
76-
printIdentity(10, o1, "10", "o1")
77-
printEquality(10, o1, "10", "o1")
74+
printIdentity(o1, 10 as NSNumber, "o1", "10")
75+
printEquality(o1, 10 as NSNumber, "o1", "10")
76+
printIdentity(10 as NSNumber, o1, "10", "o1")
77+
printEquality(10 as NSNumber, o1, "10", "o1")
7878
print("done NSObject ==")
7979
// CHECK: NSObject ==
8080
// CHECK-NEXT: o1 === o1

test/1_stdlib/NSStringAPI.swift

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -841,11 +841,6 @@ NSStringAPIs.test("init(format:locale:arguments:)") {
841841
locale: nil, arguments: args))
842842
}
843843

844-
NSStringAPIs.test("lastPathComponent") {
845-
expectEqual("bar", "/foo/bar".lastPathComponent)
846-
expectEqual("абв", "/foo/абв".lastPathComponent)
847-
}
848-
849844
NSStringAPIs.test("utf16Count") {
850845
expectEqual(1, "a".utf16.count)
851846
expectEqual(2, "\u{0001F60A}".utf16.count)
@@ -1035,11 +1030,6 @@ NSStringAPIs.test("pathComponents") {
10351030
expectEqual([ "/", "абв", "где" ] as [NSString], ("/абв/где" as NSString).pathComponents as [NSString])
10361031
}
10371032

1038-
NSStringAPIs.test("pathExtension") {
1039-
expectEqual("", "/foo/bar".pathExtension)
1040-
expectEqual("txt", "/foo/bar.txt".pathExtension)
1041-
}
1042-
10431033
NSStringAPIs.test("precomposedStringWithCanonicalMapping") {
10441034
expectEqual("abc", "abc".precomposedStringWithCanonicalMapping)
10451035
expectEqual("だくてん",
@@ -1359,26 +1349,13 @@ NSStringAPIs.test("appendingFormat(_:_:...)") {
13591349
.appendingFormat("def %@ %ld", formatArg, 42))
13601350
}
13611351

1362-
NSStringAPIs.test("appendingPathComponent(_:)") {
1363-
expectEqual("", "".appendingPathComponent(""))
1364-
expectEqual("a.txt", "".appendingPathComponent("a.txt"))
1365-
expectEqual("/tmp/a.txt", "/tmp".appendingPathComponent("a.txt"))
1366-
}
1367-
13681352
NSStringAPIs.test("appending(_:)") {
13691353
expectEqual("", "".appending(""))
13701354
expectEqual("a", "a".appending(""))
13711355
expectEqual("a", "".appending("a"))
13721356
expectEqual("\u{3099}", "".appending("\u{3099}"))
13731357
}
13741358

1375-
NSStringAPIs.test("deletingLastPathComponent") {
1376-
expectEqual("", "".deletingLastPathComponent)
1377-
expectEqual("/", "/".deletingLastPathComponent)
1378-
expectEqual("/", "/tmp".deletingLastPathComponent)
1379-
expectEqual("/tmp", "/tmp/a.txt".deletingLastPathComponent)
1380-
}
1381-
13821359
NSStringAPIs.test("folding(options:locale:)") {
13831360

13841361
func fwo(
@@ -1597,22 +1574,6 @@ NSStringAPIs.test("replacingPercentEscapes(using:)/rdar18029471")
15971574
using: .ascii))
15981575
}
15991576

1600-
NSStringAPIs.test("resolvingSymlinksInPath") {
1601-
// <rdar://problem/18030188> Difference between
1602-
// resolvingSymlinksInPath and stringByStandardizingPath is unclear
1603-
expectEqual("", "".resolvingSymlinksInPath)
1604-
expectEqual(
1605-
"/var", "/private/var/tmp////..//".resolvingSymlinksInPath)
1606-
}
1607-
1608-
NSStringAPIs.test("standardizingPath") {
1609-
// <rdar://problem/18030188> Difference between
1610-
// resolvingSymlinksInPath and standardizingPath is unclear
1611-
expectEqual("", "".standardizingPath)
1612-
expectEqual(
1613-
"/var", "/private/var/tmp////..//".standardizingPath)
1614-
}
1615-
16161577
NSStringAPIs.test("trimmingCharacters(in:)") {
16171578
expectEqual("", "".trimmingCharacters(
16181579
in: CharacterSet.decimalDigits))

test/1_stdlib/RuntimeObjC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ Reflection.test("Unmanaged/nil") {
747747
Reflection.test("Unmanaged/not-nil") {
748748
var output = ""
749749
var optionalURL: Unmanaged<CFURL>? =
750-
Unmanaged.passRetained(CFURLCreateWithString(nil, "http://llvm.org/", nil))
750+
Unmanaged.passRetained(CFURLCreateWithString(nil, "http://llvm.org/" as CFString, nil))
751751
dump(optionalURL, to: &output)
752752

753753
let expected =

test/Interpreter/SDK/Foundation_NSExpression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99

1010
// Test overlain variadic methods.
11-
let expression = NSExpression(format: "(3 + 2)**2", "LLLL", "BBBB")
11+
let expression = NSExpression(format: "(3 + 2)**2", "LLLL" as NSString, "BBBB" as NSString)
1212
let result = expression.expressionValue(with: expression, context:nil) as! NSNumber
1313
let number = result.stringValue
1414
print(number)

test/Interpreter/SDK/Foundation_NSLog.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ testNSLog()
1919
// CHECK: 1 is the loneliest number that you'll ever do
2020
NSLog(
2121
"%@ is the loneliest number that you'll ever %@",
22-
NSNumber(value: 1), "do"
22+
NSNumber(value: 1), "do" as NSString
2323
)

0 commit comments

Comments
 (0)