Files
swift-mirror/test/Constraints/issue-53296.swift
Slava Pestov 290701cb4d Sema: Ban shadowing generic parameters from outer scopes
Code like that is usually indicative of programmer error, and does not
round-trip through module interface files since there is no source
syntax to refer to an outer generic parameter.

For source compatibility this is a warning, but becomes an error with
-swift-version 6.

Fixes rdar://problem/108385980 and https://github.com/apple/swift/issues/62767.
2023-04-25 17:41:23 -04:00

27 lines
619 B
Swift

// RUN: %target-typecheck-verify-swift
// https://github.com/apple/swift/issues/53296
protocol ViewDataSource: class {
func foo<T>() -> [T]
}
class View {
weak var delegate: ViewDataSource?
}
final class ViewController<T> {
let view = View()
init() {
view.delegate = self
// expected-error@-1 {{generic class 'ViewController' requires the types 'T' and 'String' be equivalent}}
}
}
extension ViewController: ViewDataSource where T == String {
// expected-note@-1 {{requirement from conditional conformance of 'ViewController<T>' to 'ViewDataSource'}}
func foo<U>() -> [U] {
return []
}
}