Skip to content

Commit 56e47cc

Browse files
authored
Merge pull request #19269 from AnthonyLatsis/deprec-warn-in-synth-code
[Sema] Suppress deprecation warnings in synthesized code
2 parents 93c0203 + 9a05c9e commit 56e47cc

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,12 @@ void TypeChecker::diagnoseIfDeprecated(SourceRange ReferenceRange,
19371937
if (!Attr)
19381938
return;
19391939

1940+
// We don't want deprecated declarations to trigger warnings
1941+
// in synthesized code.
1942+
if (ReferenceRange.isInvalid() &&
1943+
isInsideImplicitFunction(ReferenceRange, ReferenceDC)) {
1944+
return;
1945+
}
19401946
// We match the behavior of clang to not report deprecation warnings
19411947
// inside declarations that are themselves deprecated on all deployment
19421948
// targets.

test/attr/attr_availability.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,3 +1028,24 @@ struct UnavailableAccessors {
10281028
other[alsoUnavailable: 0] += 1 // expected-error {{'subscript(alsoUnavailable:)' is unavailable: bad subscript!}} {{none}}
10291029
}
10301030
}
1031+
1032+
class BaseDeprecatedInit {
1033+
@available(*, deprecated) init(bad: Int) { }
1034+
}
1035+
1036+
class SubInheritedDeprecatedInit: BaseDeprecatedInit { }
1037+
1038+
_ = SubInheritedDeprecatedInit(bad: 0) // expected-warning {{'init(bad:)' is deprecated}}
1039+
1040+
// Should produce no warnings.
1041+
enum SR8634_Enum: Int {
1042+
case a
1043+
@available(*, deprecated, message: "I must not be raised in synthesized code")
1044+
case b
1045+
case c
1046+
}
1047+
1048+
struct SR8634_Struct: Equatable {
1049+
@available(*, deprecated, message: "I must not be raised in synthesized code", renamed: "x")
1050+
let a: Int
1051+
}

0 commit comments

Comments
 (0)