Skip to content

Add regression tests to close several issues p. 2 #59757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 28, 2022
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
35 changes: 35 additions & 0 deletions test/Interpreter/SDK/CoreFoundation_casting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,38 @@ func testCFStringAnyObjectType() {
print("done")
}
testCFStringAnyObjectType()

// https://github.com/apple/swift/issues/43022
func testOptionalCFStringToStringAndNSString() {
let optCFStr: CFString? = "Swift" as CFString

// CHECK: {{^}}Optional(Swift){{$}}
print(optCFStr)

let swiftStr1 = optCFStr as? String
let swiftStr2 = optCFStr as String?

let nsStr1 = optCFStr as? NSString
let nsStr2 = optCFStr as NSString?

if let unwrapped = swiftStr1 {
// CHECK-NEXT: {{^}}Swift{{$}}
print(unwrapped)
}
if let unwrapped = swiftStr2 {
// CHECK-NEXT: {{^}}Swift{{$}}
print(unwrapped)
}
if let unwrapped = nsStr1 {
// CHECK-NEXT: {{^}}Swift{{$}}
print(unwrapped)
}
if let unwrapped = nsStr2 {
// CHECK-NEXT: {{^}}Swift{{$}}
print(unwrapped)
}

// CHECK-NEXT: {{^}}done{{$}}
print("done")
}
testOptionalCFStringToStringAndNSString()
11 changes: 9 additions & 2 deletions test/Parse/switch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func enumElementSyntaxOnTuple() {
}
}

// sr-176
// https://github.com/apple/swift/issues/42798
enum Whatever { case Thing }
func f0(values: [Whatever]) { // expected-note {{'values' declared here}}
switch value { // expected-error {{cannot find 'value' in scope; did you mean 'values'?}}
Expand All @@ -323,7 +323,8 @@ func f0(values: [Whatever]) { // expected-note {{'values' declared here}}
}
}

// sr-720
// https://github.com/apple/swift/issues/43334
// https://github.com/apple/swift/issues/43335
enum Whichever {
case Thing
static let title = "title"
Expand All @@ -348,6 +349,12 @@ func f1(x: String, y: Whichever) {
case Whichever.title: // expected-error {{expression pattern of type 'String' cannot match values of type 'Whichever'}}
break
}
switch y {
case .alias:
break
default:
break
}
}


Expand Down
3 changes: 3 additions & 0 deletions test/stdlib/Inputs/Mirror/Mirror.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@
@interface FooMoreDerivedObjCClass : FooDerivedObjCClass
@end

@interface StringConvertibleInDebugAndOtherwise_ObjC : NSObject
@end

#endif
11 changes: 11 additions & 0 deletions test/stdlib/Inputs/Mirror/Mirror.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ @implementation FooDerivedObjCClass : FooObjCClass
@implementation FooMoreDerivedObjCClass : FooDerivedObjCClass
@end

@implementation StringConvertibleInDebugAndOtherwise_ObjC : NSObject

-(NSString *) description {
return @"description";
}

-(NSString *) debugDescription {
return @"debugDescription";
}

@end
23 changes: 15 additions & 8 deletions test/stdlib/Mirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,12 @@ func verifyWeakUnownedReflection
expectEqual(child.label, name)
expectNotNil(child.value)

// FIXME: These casts are currently broken (Dec 2019)
// Once they are fixed, enable additional checks:
//let vp1 = child.value as? WeakUnownedTestsP1
//expectNotNil(vp1)
//expectEqual(vp1!.f1(), 2)
//let vp2 = child.value as? WeakUnownedTestsP2
//expectNotNil(vp2)
//expectEqual(vp2!.f2(), "b")
let vp1 = child.value as? WeakUnownedTestsP1
expectNotNil(vp1)
expectEqual(vp1!.f1(), 2)
let vp2 = child.value as? WeakUnownedTestsP2
expectNotNil(vp2)
expectEqual(vp2!.f2(), "b")

let v = child.value as? ExpectedClass
expectNotNil(v)
Expand Down Expand Up @@ -1554,6 +1552,7 @@ mirrors.test("CustomMirrorIsInherited") {
//===----------------------------------------------------------------------===//

protocol SomeNativeProto {}
protocol SomeOtherNativeProto {}
extension Int: SomeNativeProto {}

class SomeClass {}
Expand Down Expand Up @@ -1588,6 +1587,14 @@ mirrors.test("MetatypeMirror") {
output = ""
dump(nativeProtocolConcreteMetatype, to: &output)
expectEqual(expectedNativeProtocolConcrete, output)

let nativeProtocolCompositionMetatype =
(SomeNativeProto & SomeOtherNativeProto).self
output = ""
dump(nativeProtocolCompositionMetatype, to: &output)
expectEqual(
"- Mirror.SomeNativeProto & Mirror.SomeOtherNativeProto #0\n",
output)
}
}

Expand Down
35 changes: 35 additions & 0 deletions test/stdlib/Reflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,40 @@ sanePointerString.deallocate()
var rawPointer = unsafeBitCast(0 as Int, to: Builtin.RawPointer.self)
dump(rawPointer)

// https://github.com/apple/swift/issues/43211
// CHECK-LABEL: {{^}}weak with dynamic value{{$}}
print("weak with dynamic value")
do {
class Child {}
class Example {
weak var value: Child?
}

var c: Child? = Child()
let e = Example()
e.value = c

// CHECK-NEXT: c1: Optional(Reflection.{{.*}}.Child)
// CHECK-NEXT: some: Reflection.{{.*}}.Child #0
dump(c, name: "c1")
// CHECK-NEXT: e1: Reflection.{{.*}}.Example #0
// CHECK-NEXT: value: Optional(Reflection.{{.*}}.Child)
// CHECK-NEXT: some: Reflection.{{.*}}.Child #1
dump(e, name: "e1")
// CHECK-NEXT: value1: Optional(Reflection.{{.*}}.Child)
// CHECK-NEXT: some: Reflection.{{.*}}.Child #0
dump(e.value, name: "value1")

c = nil

// CHECK-NEXT: c2: nil
dump(c, name: "c2")
// CHECK-NEXT: e2: Reflection.{{.*}}.Example #0
// CHECK-NEXT: value: nil
dump(e, name: "e2")
// CHECK-NEXT: value2: nil
dump(e.value, name: "value2")
}

// CHECK-LABEL: and now our song is done
print("and now our song is done")
9 changes: 6 additions & 3 deletions test/stdlib/RuntimeObjC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -740,14 +740,17 @@ Reflection.test("Name of metatype of artificial subclass") {
expectEqual(String(reflecting: type(of: obj)), "a.TestArtificialSubclass")
}

@objc class StringConvertibleInDebugAndOtherwise : NSObject {
@objc class StringConvertibleInDebugAndOtherwise_Native : NSObject {
override var description: String { return "description" }
override var debugDescription: String { return "debugDescription" }
}

Reflection.test("NSObject is properly CustomDebugStringConvertible") {
let object = StringConvertibleInDebugAndOtherwise()
expectEqual(String(reflecting: object), object.debugDescription)
let objectNative = StringConvertibleInDebugAndOtherwise_Native()
let objectObjC = StringConvertibleInDebugAndOtherwise_ObjC()

expectEqual(String(reflecting: objectNative), objectNative.debugDescription)
expectEqual(String(reflecting: objectObjC), objectObjC.debugDescription)
}

Reflection.test("NSRange QuickLook") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not %target-swift-frontend %s -typecheck

// https://github.com/apple/swift/issues/43187
// RUN: %target-swift-ide-test -structure -source-filename=%s

for
{({{{class
case,
Expand Down