Skip to content

[Sema] Suppress deprecation warnings in synthesized code #19269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,12 @@ void TypeChecker::diagnoseIfDeprecated(SourceRange ReferenceRange,
if (!Attr)
return;

// We don't want deprecated declarations to trigger warnings
// in synthesized code.
if (ReferenceRange.isInvalid() &&
isInsideImplicitFunction(ReferenceRange, ReferenceDC)) {
return;
}
// We match the behavior of clang to not report deprecation warnings
// inside declarations that are themselves deprecated on all deployment
// targets.
Expand Down
21 changes: 21 additions & 0 deletions test/attr/attr_availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1028,3 +1028,24 @@ struct UnavailableAccessors {
other[alsoUnavailable: 0] += 1 // expected-error {{'subscript(alsoUnavailable:)' is unavailable: bad subscript!}} {{none}}
}
}

class BaseDeprecatedInit {
@available(*, deprecated) init(bad: Int) { }
}

class SubInheritedDeprecatedInit: BaseDeprecatedInit { }

_ = SubInheritedDeprecatedInit(bad: 0) // expected-warning {{'init(bad:)' is deprecated}}

// Should produce no warnings.
enum SR8634_Enum: Int {
case a
@available(*, deprecated, message: "I must not be raised in synthesized code")
case b
case c
}

struct SR8634_Struct: Equatable {
@available(*, deprecated, message: "I must not be raised in synthesized code", renamed: "x")
let a: Int
}