Files
swift-mirror/test/Serialization/Inputs/def_transparent.swift
Slava Pestov f63dff16c7 AST: Don't allow @_transparent on extensions
Quiz: What does @_transparent on an extension actually *do*?

1) Make all members @_transparent?
2) Allow your members to be @_transparent?
3) Some other magical effect that has nothing to do with members?

The correct answer is 1), however a few places in the stdlib defined
a @_transparent extension and then proceeded to make some or all members
also @_transparent, and in a couple of places we defined a @_transparent
extension with no members at all.

To avoid cargo culting and confusion, remove the ability to make
@_transparent extensions altogether, and force usages to be explicit.
2016-11-01 21:14:09 -07:00

92 lines
1.4 KiB
Swift

@_transparent public func testTransparent(x x: Bool) -> Bool {
return x
}
@_transparent public func testBuiltin() -> Int32 {
var y: Int32 = 300
var z = "foo"
return y
}
@_transparent public func standalone_function(x x: Int32, y: Int32) -> Int32 {
return x
}
public func foo() -> Int32 { return 0 }
public func runced() -> Bool { return true }
public func a() {}
public func b() {}
public func c() {}
public func d() {}
public func e() {}
@_transparent public func test_br() {
switch foo() {
case _ where runced():
a()
case _:
b()
}
c()
}
public enum MaybePair {
case Neither
case Left(Int32)
case Right(String)
case Both(Int32, String)
}
public func do_switch(u u: MaybePair) {
switch u {
case .Neither:
a()
case .Left:
b()
case .Right:
c()
case .Both:
d()
}
e()
}
public struct Wrapper {
public var value: Int32
@_transparent public init(Val: Int32) {
value = Val
}
@_transparent public func getValue() -> Int32 {
return value
}
public var valueAgain: Int32 {
@_transparent
get {
return value
}
}
}
public extension Wrapper {
@_transparent
func getValueAgain() -> Int32 {
return self.value
}
}
public protocol P {
func f() -> Self
}
public protocol CP : class {
func f() -> Self
}
@_transparent public
func open_existentials(p p: P, cp: CP) {
p.f()
cp.f()
}