mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The rule changes are as follows: * All functions (introduced with the 'func' keyword) have argument labels for arguments beyond the first, by default. Methods are no longer special in this regard. * The presence of a default argument no longer implies an argument label. The actual changes to the parser and printer are fairly simple; the rest of the noise is updating the standard library, overlays, tests, etc. With the standard library, this change is intended to be API neutral: I've added/removed #'s and _'s as appropriate to keep the user interface the same. If we want to separately consider using argument labels for more free functions now that the defaults in the language have shifted, we can tackle that separately. Fixes rdar://problem/17218256. Swift SVN r27704
73 lines
2.0 KiB
Swift
73 lines
2.0 KiB
Swift
// RUN: rm -rf %t && mkdir %t
|
|
// RUN: %target-build-swift -module-name MangleTest %s -o %t/a.out
|
|
// RUN: %target-run %t/a.out | FileCheck %s
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
|
|
/* FIXME: SwiftObject doesn't support -description
|
|
class Foo { }
|
|
var anyFoo: AnyObject = Foo()
|
|
println(anyFoo.description())
|
|
|
|
@objc class Bar { }
|
|
var anyBar: AnyObject = Bar()
|
|
println(anyBar.description())
|
|
*/
|
|
|
|
func checkClassName(cls: AnyClass, _ name: String, _ mangled: String)
|
|
{
|
|
// Class's name should appear unmangled.
|
|
assert(NSStringFromClass(cls) == name)
|
|
assert(NSStringFromClass(object_getClass(cls)) == name)
|
|
|
|
// Look up by unmangled name should work.
|
|
// Look up by mangled name should also work.
|
|
for query in [name, mangled] {
|
|
let cls2 = NSClassFromString(query)
|
|
assert(cls === cls2)
|
|
assert(object_getClass(cls) === object_getClass(cls2))
|
|
}
|
|
}
|
|
|
|
func checkProtocolName(proto: Protocol, _ name: String, _ mangled: String)
|
|
{
|
|
// Protocol's name should appear unmangled.
|
|
assert(NSStringFromProtocol(proto) == name)
|
|
|
|
// Look up by unmangled name should work.
|
|
// Look up by mangled name should also work.
|
|
for query in [name, mangled] {
|
|
let proto2 = NSProtocolFromString(query)
|
|
assert(protocol_isEqual(proto, proto2))
|
|
}
|
|
}
|
|
|
|
func checkIvarName(cls: AnyClass, _ name: String)
|
|
{
|
|
assert(name == String.fromCString(ivar_getName(class_getInstanceVariable(cls, name))))
|
|
}
|
|
|
|
|
|
@objc class Wibble : NSObject { }
|
|
checkClassName(Wibble.self, "MangleTest.Wibble", "_TtC10MangleTest6Wibble")
|
|
|
|
// Check whether the class name comes out properly in the instance description
|
|
var anyWibble: AnyObject = Wibble()
|
|
println(anyWibble.description)
|
|
// CHECK: MangleTest.Wibble
|
|
|
|
|
|
// ObjC metadata is not punycoded.
|
|
|
|
@objc protocol RadicalHeart⺖ { }
|
|
checkProtocolName(RadicalHeart⺖.self, "MangleTest.RadicalHeart⺖", "_TtP10MangleTest15RadicalHeart⺖_")
|
|
|
|
@objc class RadicalSheep⽺ : RadicalHeart⺖ {
|
|
var ⽺x: Int = 0
|
|
}
|
|
checkClassName(RadicalSheep⽺.self,
|
|
"MangleTest.RadicalSheep⽺", "_TtC10MangleTest15RadicalSheep⽺")
|
|
checkIvarName(RadicalSheep⽺.self, "⽺x")
|