Skip to content

Commit d8756fd

Browse files
committed
[RequirementMachine] Downgrade concrete type parameter diagnostics to a
warning. These diagnostics are stricter in the RequirementMachine than in the GSB, and there's code that relies on the more relaxed diagnostics in the source compatibility suite. Downgrade these diagnostics to a warning using warnUntilSwiftVersion(6).
1 parent b6e360b commit d8756fd

11 files changed

+21
-19
lines changed

lib/AST/RequirementMachine/RequirementMachineRequests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,11 +908,13 @@ InferredGenericSignatureRequestRQM::evaluate(
908908

909909
if (canonical->isTypeParameter()) {
910910
ctx.Diags.diagnose(loc, diag::requires_generic_params_made_equal,
911-
genericParam, result->getSugaredType(canonical));
911+
genericParam, result->getSugaredType(canonical))
912+
.warnUntilSwiftVersion(6);
912913
} else {
913914
ctx.Diags.diagnose(loc,
914915
diag::requires_generic_param_made_equal_to_concrete,
915-
genericParam);
916+
genericParam)
917+
.warnUntilSwiftVersion(6);
916918
}
917919
}
918920
}

test/Compatibility/accessibility.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ struct DefaultGeneric<T> {}
503503

504504
struct DefaultGenericPrivate<T: PrivateProto> {} // expected-error {{generic struct must be declared private or fileprivate because its generic parameter uses a private type}}
505505
struct DefaultGenericPrivate2<T: PrivateClass> {} // expected-error {{generic struct must be declared private or fileprivate because its generic parameter uses a private type}}
506-
struct DefaultGenericPrivateReq<T> where T == PrivateClass {} // expected-error {{same-type requirement makes generic parameter 'T' non-generic}}
506+
struct DefaultGenericPrivateReq<T> where T == PrivateClass {} // expected-warning {{same-type requirement makes generic parameter 'T' non-generic}}
507507
// expected-error@-1 {{generic struct must be declared private or fileprivate because its generic requirement uses a private type}}
508508
struct DefaultGenericPrivateReq2<T> where T: PrivateProto {} // expected-error {{generic struct must be declared private or fileprivate because its generic requirement uses a private type}}
509509

test/Constraints/generic_super_constraint.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func foo<T>(_ x: T) -> Derived where T: Base<Int>, T: Derived {
99
}
1010

1111
// FIXME: There is no explicit same-type requirement written.
12-
// expected-error@+1{{same-type requirement makes generic parameter 'T' non-generic}}
12+
// expected-warning@+1{{same-type requirement makes generic parameter 'T' non-generic}}
1313
func bar<T, U>(_ x: U, y: T) -> (Derived, Int) where U: Base<T>, U: Derived {
1414
return (x, y)
1515
}

test/Generics/concrete_contraction_unrelated_typealias.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class ConcreteDelegateProxy {
5353
// CHECK-LABEL: .ConcreteDelegateProxy.init(_:_:_:)@
5454
// CHECK-NEXT: <P, D, Proxy where P == SomeClass, D == SomeStruct, Proxy : ConcreteDelegateProxy, Proxy : DelegateProxyType, Proxy.[DelegateProxyType]Delegate == SomeStruct, Proxy.[DelegateProxyType]Parent == SomeClass>
5555

56-
// expected-error@+2 {{same-type requirement makes generic parameter 'P' non-generic}}
57-
// expected-error@+1 {{same-type requirement makes generic parameter 'D' non-generic}}
56+
// expected-warning@+2 {{same-type requirement makes generic parameter 'P' non-generic}}
57+
// expected-warning@+1 {{same-type requirement makes generic parameter 'D' non-generic}}
5858
init<P, D, Proxy: DelegateProxyType>(_: P, _: D, _: Proxy.Type)
5959
where Proxy: ConcreteDelegateProxy,
6060
Proxy.Parent == P,

test/Generics/function_defs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,4 @@ func badTypeConformance7<T, U>(_: T, _: U) where T? : U { }
301301

302302
func badSameType<T, U : GeneratesAnElement, V>(_ : T, _ : U)
303303
where T == U.Element, U.Element == V {}
304-
// expected-error@-2{{same-type requirement makes generic parameters 'V' and 'T' equivalent}}
304+
// expected-warning@-2{{same-type requirement makes generic parameters 'V' and 'T' equivalent}}

test/Generics/requirement_machine_diagnostics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func concreteSameTypeRedundancy<T>(_: T) where Int == Int {}
4747

4848
func concreteSameTypeRedundancy<T>(_: T) where Array<Int> == Array<T> {}
4949
// expected-warning@-1{{redundant same-type constraint 'Array<Int>' == 'Array<T>'}}
50-
// expected-error@-2{{same-type requirement makes generic parameter 'T' non-generic}}
50+
// expected-warning@-2{{same-type requirement makes generic parameter 'T' non-generic}}
5151

5252
protocol P {}
5353
struct S: P {}
@@ -199,7 +199,7 @@ func inferred6<T : P11>(_: T) where T.Y : Hashable, T.Z == Set<T.X>, T.X == T.Y
199199
func typeMatcherSugar<T>(_: T) where Array<Int> == Array<T>, Array<Int> == Array<T> {}
200200
// expected-warning@-1 2{{redundant same-type constraint 'Array<Int>' == 'Array<T>'}}
201201
// expected-warning@-2{{redundant same-type constraint 'T' == 'Int'}}
202-
// expected-error@-3{{same-type requirement makes generic parameter 'T' non-generic}}
202+
// expected-warning@-3{{same-type requirement makes generic parameter 'T' non-generic}}
203203

204204

205205
struct ConcreteSelf: ConcreteProtocol {}

test/Generics/superclass_constraint_nested_type.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-typecheck-verify-swift
2-
// RUN: not %target-swift-frontend -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s
2+
// RUN: %target-swift-frontend -typecheck -verify %s -debug-generic-signatures 2>&1 | %FileCheck %s
33

44
// rdar://problem/39481178 - Introducing a superclass constraint does not add
55
// same-type constraints on nested types
@@ -19,10 +19,10 @@ extension P {
1919
// CHECK-LABEL: .f1@
2020
// CHECK-NEXT: <Self, T where Self : C, T == Int>
2121
func f1<T>(_: T) where T == Q, Self : C {}
22-
// expected-error@-1 {{same-type requirement makes generic parameter 'T' non-generic}}
22+
// expected-warning@-1 {{same-type requirement makes generic parameter 'T' non-generic}}
2323

2424
// CHECK-LABEL: .f2@
2525
// CHECK-NEXT: <Self, T where Self : C, T == Int>
2626
func f2<T>(_: T) where Self : C, T == Q {}
27-
// expected-error@-1 {{same-type requirement makes generic parameter 'T' non-generic}}
27+
// expected-warning@-1 {{same-type requirement makes generic parameter 'T' non-generic}}
2828
}

test/IDE/print_usrs_opaque_types.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// CHECK: [[@LINE+1]]:{{[0-9]+}} s:14swift_ide_test0C21UnifyingGenericParams1xQrx_tq_Rszr0_lF
99
func testUnifyingGenericParams<T, U>(x: T) -> some Collection where T == U {
10-
// expected-error@-1 {{same-type requirement makes generic parameters 'U' and 'T' equivalent}}
10+
// expected-warning@-1 {{same-type requirement makes generic parameters 'U' and 'T' equivalent}}
1111
return []
1212
}
1313

@@ -18,14 +18,14 @@ func testUnifyingGenericParams2<T, U>(x: T) -> some Collection where T: Collecti
1818

1919
// CHECK: [[@LINE+1]]:{{[0-9]+}} s:14swift_ide_test0C24ConcretizingGenericParam1xQrSi_tSiRszlF
2020
func testConcretizingGenericParam<T>(x: T) -> some Collection where T == Int {
21-
// expected-error@-1 {{same-type requirement makes generic parameter 'T' non-generic}}
21+
// expected-warning@-1 {{same-type requirement makes generic parameter 'T' non-generic}}
2222
return []
2323
}
2424

2525
struct GenericContext<T> {
2626
// CHECK: [[@LINE+1]]:{{[0-9]+}} s:14swift_ide_test14GenericContextV0c8UnifyingD6Params1xQrx_tqd__RszlF
2727
func testUnifyingGenericParams<U>(x: T) -> some Collection where T == U {
28-
// expected-error@-1 {{same-type requirement makes generic parameters 'U' and 'T' equivalent}}
28+
// expected-warning@-1 {{same-type requirement makes generic parameters 'U' and 'T' equivalent}}
2929
return []
3030
}
3131

@@ -36,7 +36,7 @@ struct GenericContext<T> {
3636

3737
// CHECK: [[@LINE+1]]:{{[0-9]+}} s:14swift_ide_test14GenericContextVyQrxcqd__Rszluip
3838
subscript<U>(x: T) -> some Collection where T == U {
39-
// expected-error@-1 {{same-type requirement makes generic parameters 'U' and 'T' equivalent}}
39+
// expected-warning@-1 {{same-type requirement makes generic parameters 'U' and 'T' equivalent}}
4040
// CHECK: [[@LINE+1]]:{{[0-9]+}} s:14swift_ide_test14GenericContextVyQrxcqd__Rszluig
4141
get {
4242
return []

test/Sema/accessibility.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ struct DefaultGeneric<T> {}
520520

521521
struct DefaultGenericPrivate<T: PrivateProto> {} // expected-error {{generic struct must be declared private or fileprivate because its generic parameter uses a private type}}
522522
struct DefaultGenericPrivate2<T: PrivateClass> {} // expected-error {{generic struct must be declared private or fileprivate because its generic parameter uses a private type}}
523-
struct DefaultGenericPrivateReq<T> where T == PrivateClass {} // expected-error {{same-type requirement makes generic parameter 'T' non-generic}}
523+
struct DefaultGenericPrivateReq<T> where T == PrivateClass {} // expected-warning {{same-type requirement makes generic parameter 'T' non-generic}}
524524
// expected-error@-1 {{generic struct must be declared private or fileprivate because its generic requirement uses a private type}}
525525
struct DefaultGenericPrivateReq2<T> where T: PrivateProto {} // expected-error {{generic struct must be declared private or fileprivate because its generic requirement uses a private type}}
526526

test/decl/typealias/generic.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typealias DS<T> = MyType<String, T>
3333
typealias BadA<T : Int> = MyType<String, T> // expected-error {{type 'T' constrained to non-protocol, non-class type 'Int'}}
3434

3535
typealias BadB<T where T == Int> = MyType<String, T> // expected-error {{associated types must not have a generic parameter list}}
36-
// expected-error@-1 {{same-type requirement makes generic parameter 'T' non-generic}}
36+
// expected-warning@-1 {{same-type requirement makes generic parameter 'T' non-generic}}
3737

3838
typealias BadC<T,T> = MyType<String, T> // expected-error {{invalid redeclaration of 'T'}}
3939
// expected-note @-1 {{'T' previously declared here}}

test/decl/typealias/protocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ protocol P9 {
254254
typealias A = Int
255255
}
256256

257-
func testT9a<T: P9, U>(_: T, _: U) where T.A == U { } // expected-error {{same-type requirement makes generic parameter 'U' non-generic}}
257+
func testT9a<T: P9, U>(_: T, _: U) where T.A == U { } // expected-warning {{same-type requirement makes generic parameter 'U' non-generic}}
258258
func testT9b<T: P9>(_: T) where T.A == Float { } // expected-error{{no type for 'T.A' can satisfy both 'T.A == Int' and 'T.A == Float'}}
259259

260260

0 commit comments

Comments
 (0)