Files
swift-mirror/test/Interpreter/generic_struct.swift
Dmitri Hrybenko de9a0c8ff0 stdlib/printing: remove ReplPrintable protocol
It is replaced by debugPrint() family of functions, that are called by REPL.

There is a regression in printing types that don't conform to Printable, this
is tracked by rdar://16898708


Swift SVN r18006
2014-05-13 16:22:56 +00:00

55 lines
1.0 KiB
Swift

// RUN: rm -rf %t && mkdir %t
// RUN: %target-build-swift -Xfrontend -enable-dynamic-value-type-layout %s -o %t/a.out
// RUN: %target-run %t/a.out | FileCheck %s
protocol MyPrintable {
func myPrint()
}
extension Int : MyPrintable {
func myPrint() {
print(self.description)
}
}
extension String : MyPrintable {
func myPrint() {
print(self.debugDescription)
}
}
struct BufferedPair<T, U> {
var front: UInt8
var first: T
var second: U
var back: UInt8
}
enum State : MyPrintable {
case CA, OR, WA
func myPrint() {
switch self {
case .CA:
print("California")
case .OR:
print("Oregon")
case .WA:
print("Washington")
}
}
}
func printPair<A : MyPrintable, B : MyPrintable>(p: BufferedPair<A,B>) {
print("\(p.front) ")
p.first.myPrint()
print(" ")
p.second.myPrint()
println(" \(p.back)")
}
var p = BufferedPair(front: 219, first: State.OR, second: "Idaho's Portugal",
back: 17)
// CHECK: 219 Oregon "Idaho\'s Portugal" 17
printPair(p)