Files
swift-mirror/test/decl/ext/specialize.swift
Slava Pestov 6cc12123b0 Add test case for formerly missing diagnostic
We didn't diagnose conflicting generic signatures involving the
SE-0361 syntax before https://github.com/swiftlang/swift/pull/81304.

Fixes rdar://152170450.
2025-05-30 11:32:03 -04:00

95 lines
2.0 KiB
Swift

// RUN: %target-typecheck-verify-swift
extension Array<Int> {
func someIntFuncOnArray() {}
}
let _ = [0, 1, 2].someIntFuncOnArray()
extension [Character] {
func makeString() -> String { fatalError() }
}
let _ = ["a", "b", "c"].makeString()
let _ = [1, 2, 3].makeString() // expected-error 3 {{cannot convert value of type 'Int' to expected element type 'Character'}}
extension Set<_> {} // expected-error {{cannot extend a type that contains placeholders}}
// https://github.com/apple/swift/issues/47452
struct Foo<T, U> {
var x: T
var y: U
}
typealias IntFoo<U> = Foo<Int, U>
extension IntFoo where U == Int {
func hello() {
print("hello")
}
}
Foo(x: "test", y: 1).hello()
struct MyType<TyA, TyB> {
var a : TyA, b : TyB
}
typealias A<T1, T2> = MyType<T2, T1>
extension A {}
extension A<Float, Int> {}
extension A<Void, Void> {}
struct Tree<T> {
struct Branch<B> {
struct Nest<N> {
struct Egg {}
}
}
}
extension Tree.Branch.Nest.Egg { static func tweet() {} }
extension Tree<Int>.Branch.Nest.Egg { static func twoot() {} }
extension Tree<Int>.Branch<String>.Nest.Egg { static func twote() {} }
extension Tree<Int>.Branch<String>.Nest<Void>.Egg { static func twite() {} }
func testNestedExtensions() {
do {
Tree<Void>.Branch<Void>.Nest<Void>.Egg.tweet()
}
do {
Tree<Int>.Branch<Void>.Nest<Void>.Egg.twoot()
Tree<Int>.Branch<Int>.Nest<Void>.Egg.twoot()
Tree<Int>.Branch<Int>.Nest<Int>.Egg.twoot()
}
do {
Tree<Int>.Branch<String>.Nest<Void>.Egg.twote()
Tree<Int>.Branch<String>.Nest<Float>.Egg.twote()
}
Tree<Int>.Branch<String>.Nest<Void>.Egg.twite()
}
// rdar://111059036 - failed to produce a diagnostic in specialized extension
struct Test {
struct Key<Value> {}
}
class State {
}
extension Test.Key<State> {
static let state = Self<State>()
}
protocol P {}
struct S: P {}
extension Sequence<any P> where Self == [S] {}
// expected-error@-1 {{generic signature requires types 'S' and 'any P' to be the same}}