Skip to content

Commit 412559a

Browse files
committed
Add test cases for a few bugs that seem to be fixed already
Cleaning out some old JIRAs, don't want these to regress...
1 parent e65d867 commit 412559a

File tree

10 files changed

+196
-0
lines changed

10 files changed

+196
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %target-swift-frontend %s -emit-ir
2+
3+
enum SampleType: UInt8 {
4+
case Value = 1
5+
case Array
6+
case Dictionary
7+
}
8+
9+
protocol ByteConvertible {
10+
init?(bytes: [UInt8], startOffset: Int)
11+
func rawBytes() -> [UInt8]
12+
func bytesNeeded() -> Int
13+
}
14+
15+
protocol TypeRequestable {
16+
static func containerType() -> SampleType
17+
}
18+
19+
struct Sample<T, C where T: ByteConvertible, C: TypeRequestable> {
20+
let numberOfRecords: UInt32
21+
let sizeInBytes: UInt64
22+
var records: [T] = [] // problem line
23+
24+
init(records: [T]) {
25+
numberOfRecords = 0
26+
sizeInBytes = 0
27+
28+
self.records.reserveCapacity(records.count)
29+
self.records += records
30+
}
31+
}
32+
33+
extension Sample: ByteConvertible {
34+
init?(bytes: [UInt8], startOffset: Int = 0) {
35+
numberOfRecords = 0
36+
sizeInBytes = 0
37+
records = []
38+
}
39+
40+
func rawBytes() -> [UInt8] {
41+
return []
42+
}
43+
44+
func bytesNeeded() -> Int {
45+
return 0
46+
}
47+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-frontend %s -emit-ir
2+
3+
public protocol Proto {
4+
associatedtype One
5+
associatedtype Two
6+
7+
static func bar<T>(elm: One, t: T) -> T
8+
}
9+
10+
struct S<P: Proto> {
11+
let x: P.Two
12+
func foo<T>(_ t: T) -> T where P.Two == P.One {
13+
let x: P.Two = self.x
14+
let elm: P.One = x as! P.One
15+
return P.bar(elm: elm, t: t)
16+
}
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-frontend %s -emit-ir
2+
3+
protocol Foo {
4+
associatedtype A
5+
var value: A { get }
6+
init(_ v: A)
7+
}
8+
extension Foo {
9+
init<T>(pairing other: T)
10+
where
11+
T: Foo,
12+
Self.A == (T.A, T.A) // <-- Look at this, and then at the error below.
13+
{
14+
let otherValuePaired = (other.value, other.value)
15+
let v: A = otherValuePaired // <-- Error: Cannot convert value of
16+
self.init(v) // type '(T.A, T.A)' to specified type 'Self.A'
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend %s -emit-ir
2+
3+
public class Entity{
4+
}
5+
public class DataCollection<T>{
6+
}
7+
public protocol IEntityCollection : class{
8+
func AddEntity(_ entity:Entity)
9+
}
10+
public class EntityCollection<T:Entity> : DataCollection<T>, IEntityCollection{
11+
public func AddEntity(_ entity: Entity) {}
12+
}
13+
public class EntityReference2<TParentEntityCollection:EntityCollection<TParentEntity>, TChildEntityCollection:EntityCollection<TChildEntity>, TChildEntity:Entity, TParentEntity:Entity>
14+
{
15+
public let i = 0
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-frontend %s -emit-silgen
2+
3+
protocol CType {
4+
init()
5+
}
6+
7+
protocol BType {
8+
associatedtype C: CType
9+
}
10+
11+
protocol A {
12+
associatedtype B: BType
13+
typealias C = B.C
14+
}
15+
16+
func test<T: A>(_ a: T) -> T.C {
17+
return T.C()
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-frontend %s -typecheck
2+
3+
protocol P {
4+
associatedtype A
5+
}
6+
7+
struct S : P {
8+
typealias A = Gen<S>
9+
}
10+
11+
struct Gen<T: P> {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-frontend %s -emit-ir
2+
3+
enum Value {
4+
case IntValue(Int)
5+
}
6+
7+
protocol Storable {
8+
associatedtype Representation
9+
10+
static var storageKey : String? { get }
11+
var representation : Representation { get }
12+
}
13+
14+
protocol RawProducable {
15+
var rawValueForType : Int16 { get }
16+
init<T: Storable where T.Representation == Self>(value: T)
17+
}
18+
19+
extension Int : Storable {
20+
static var storageKey : String? { return "int64Value" }
21+
var representation : Value { return Value.IntValue(self) }
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend %s -emit-ir
2+
3+
public class A <T> {
4+
public init() {}
5+
}
6+
7+
public class B : A <B.C> {
8+
public struct C { }
9+
public override init() {}
10+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-swift-frontend %s -emit-ir
2+
3+
protocol P {
4+
associatedtype A
5+
func f()
6+
}
7+
8+
extension P where A == Int {
9+
func f() {
10+
print("cool")
11+
}
12+
}
13+
extension P {
14+
func f() { print("semi-uncool") }
15+
func g() {
16+
f()
17+
}
18+
}
19+
struct X<T> : P {
20+
typealias A = T
21+
}
22+
23+
extension X where A == Int {
24+
func f() {
25+
print("cool2")
26+
}
27+
}
28+
29+
X<Int>().f()
30+
X<Int>().g()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-frontend %s -emit-ir
2+
3+
extension Array where Iterator.Element == UTF8.CodeUnit {
4+
var u8str : String {
5+
return ""
6+
}
7+
}

0 commit comments

Comments
 (0)