Skip to content

Add test cases for a few bugs that seem to be fixed already #6553

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
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
47 changes: 47 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0047-sr1307.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// RUN: %target-swift-frontend %s -emit-ir

enum SampleType: UInt8 {
case Value = 1
case Array
case Dictionary
}

protocol ByteConvertible {
init?(bytes: [UInt8], startOffset: Int)
func rawBytes() -> [UInt8]
func bytesNeeded() -> Int
}

protocol TypeRequestable {
static func containerType() -> SampleType
}

struct Sample<T, C where T: ByteConvertible, C: TypeRequestable> {
let numberOfRecords: UInt32
let sizeInBytes: UInt64
var records: [T] = [] // problem line

init(records: [T]) {
numberOfRecords = 0
sizeInBytes = 0

self.records.reserveCapacity(records.count)
self.records += records
}
}

extension Sample: ByteConvertible {
init?(bytes: [UInt8], startOffset: Int = 0) {
numberOfRecords = 0
sizeInBytes = 0
records = []
}

func rawBytes() -> [UInt8] {
return []
}

func bytesNeeded() -> Int {
return 0
}
}
17 changes: 17 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0048-sr2333.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %target-swift-frontend %s -emit-ir

public protocol Proto {
associatedtype One
associatedtype Two

static func bar<T>(elm: One, t: T) -> T
}

struct S<P: Proto> {
let x: P.Two
func foo<T>(_ t: T) -> T where P.Two == P.One {
let x: P.Two = self.x
let elm: P.One = x as! P.One
return P.bar(elm: elm, t: t)
}
}
18 changes: 18 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0049-sr2611.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %target-swift-frontend %s -emit-ir

protocol Foo {
associatedtype A
var value: A { get }
init(_ v: A)
}
extension Foo {
init<T>(pairing other: T)
where
T: Foo,
Self.A == (T.A, T.A) // <-- Look at this, and then at the error below.
{
let otherValuePaired = (other.value, other.value)
let v: A = otherValuePaired // <-- Error: Cannot convert value of
self.init(v) // type '(T.A, T.A)' to specified type 'Self.A'
}
}
16 changes: 16 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0050-sr3159.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %target-swift-frontend %s -emit-ir

public class Entity{
}
public class DataCollection<T>{
}
public protocol IEntityCollection : class{
func AddEntity(_ entity:Entity)
}
public class EntityCollection<T:Entity> : DataCollection<T>, IEntityCollection{
public func AddEntity(_ entity: Entity) {}
}
public class EntityReference2<TParentEntityCollection:EntityCollection<TParentEntity>, TChildEntityCollection:EntityCollection<TChildEntity>, TChildEntity:Entity, TParentEntity:Entity>
{
public let i = 0
}
18 changes: 18 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0051-sr3212.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %target-swift-frontend %s -emit-silgen

protocol CType {
init()
}

protocol BType {
associatedtype C: CType
}

protocol A {
associatedtype B: BType
typealias C = B.C
}

func test<T: A>(_ a: T) -> T.C {
return T.C()
}
11 changes: 11 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0052-sr3478.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %target-swift-frontend %s -typecheck

protocol P {
associatedtype A
}

struct S : P {
typealias A = Gen<S>
}

struct Gen<T: P> {}
22 changes: 22 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0053-sr490.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %target-swift-frontend %s -emit-ir

enum Value {
case IntValue(Int)
}

protocol Storable {
associatedtype Representation

static var storageKey : String? { get }
var representation : Representation { get }
}

protocol RawProducable {
var rawValueForType : Int16 { get }
init<T: Storable where T.Representation == Self>(value: T)
}

extension Int : Storable {
static var storageKey : String? { return "int64Value" }
var representation : Value { return Value.IntValue(self) }
}
10 changes: 10 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0054-sr833.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %target-swift-frontend %s -emit-ir

public class A <T> {
public init() {}
}

public class B : A <B.C> {
public struct C { }
public override init() {}
}
30 changes: 30 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0057-rdar29587093.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// RUN: %target-swift-frontend %s -emit-ir

protocol P {
associatedtype A
func f()
}

extension P where A == Int {
func f() {
print("cool")
}
}
extension P {
func f() { print("semi-uncool") }
func g() {
f()
}
}
struct X<T> : P {
typealias A = T
}

extension X where A == Int {
func f() {
print("cool2")
}
}

X<Int>().f()
X<Int>().g()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-swift-frontend %s -emit-ir

extension Array where Iterator.Element == UTF8.CodeUnit {
var u8str : String {
return ""
}
}