mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Conformances that discoverably for a type parameter via a superclass requirement occupy a bit of a gray area in the type checker and generic signature handling right now: we have a type parameter (so the paths that handle concrete conformances don't kick in), but the conformance itself isn't modeled as a requirement because it is available via lookup. Teach SubstitutionMap's conformance lookup to detect this case and perform conformance lookup in the generic signature (i.e., falling back to global lookup) in this case, replicating the hack that IRGen uses to address the same issue when accessing the conformance (see GenArchetype.cpp's TODO where we lookup a conformance on the superclass). The removal of that hack (as well as this one) are tracked by rdar://problem/34609744. For now, fixes SR-7072 / rdar://problem/37904576.
32 lines
841 B
Swift
32 lines
841 B
Swift
// RUN: %target-swift-frontend %s -emit-sil -o - | %FileCheck %s
|
|
|
|
public final class GenClass<Element: Cl> {
|
|
public subscript(index: Int) -> Element {
|
|
get { return unsafeBitCast(0, to: Element.self) }
|
|
}
|
|
}
|
|
|
|
public protocol Proto { }
|
|
|
|
public struct Iter<Element: Proto>: IteratorProtocol {
|
|
public mutating func next() -> Element? { return nil }
|
|
}
|
|
|
|
extension GenClass: RandomAccessCollection {
|
|
public func makeIterator() -> Iter<Element> { return Iter() }
|
|
public var startIndex: Int { return 0 }
|
|
public var endIndex: Int { return 0 }
|
|
}
|
|
|
|
open class Cl: Proto { }
|
|
|
|
class Bar: Cl {
|
|
var x: Int?
|
|
}
|
|
|
|
// CHECK-LABEL: sil hidden @$S4main5crash4barsSbAA8GenClassCyAA3BarCG_tF
|
|
func crash(bars: GenClass<Bar>) -> Bool {
|
|
// CHECK: apply [[FN:%.*]]<Bar, [Bar]>
|
|
return Array(bars.filter { $0.x == nil }).isEmpty
|
|
}
|