Skip to content

Frontend: Deprecate -warn-on-potentially-unavailable-enum-case option #68009

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
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
3 changes: 0 additions & 3 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ namespace swift {
/// Should conformance availability violations be diagnosed as errors?
bool EnableConformanceAvailabilityErrors = false;

/// Should potential unavailability on enum cases be downgraded to a warning?
bool WarnOnPotentiallyUnavailableEnumCase = false;

/// Should the editor placeholder error be downgraded to a warning?
bool WarnOnEditorPlaceholder = false;

Expand Down
2 changes: 1 addition & 1 deletion include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def disable_conformance_availability_errors : Flag<["-"],

def warn_on_potentially_unavailable_enum_case : Flag<["-"],
"warn-on-potentially-unavailable-enum-case">,
HelpText<"Downgrade potential unavailability of enum case to a warning">;
HelpText<"Deprecated, will be removed in future versions">;

def warn_on_editor_placeholder : Flag<["-"],
"warn-on-editor-placeholder">,
Expand Down
4 changes: 0 additions & 4 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
arguments.push_back("-aarch64-use-tbi");
}

if (output.getPrimaryOutputType() == file_types::TY_SwiftModuleFile) {
arguments.push_back("-warn-on-potentially-unavailable-enum-case");
}

// Enable or disable ObjC interop appropriately for the platform
if (Triple.isOSDarwin()) {
arguments.push_back("-enable-objc-interop");
Expand Down
5 changes: 3 additions & 2 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
if (Args.hasArg(OPT_check_api_availability_only))
Diags.diagnose(SourceLoc(), diag::warn_flag_deprecated,
"-check-api-availability-only");
if (Args.hasArg(OPT_warn_on_potentially_unavailable_enum_case))
Diags.diagnose(SourceLoc(), diag::warn_flag_deprecated,
"-warn-on-potentially-unavailable-enum-case");

if (const Arg *A = Args.getLastArg(OPT_unavailable_decl_optimization_EQ)) {
auto value =
Expand All @@ -667,8 +670,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
= A->getOption().matches(OPT_enable_conformance_availability_errors);
}

Opts.WarnOnPotentiallyUnavailableEnumCase |=
Args.hasArg(OPT_warn_on_potentially_unavailable_enum_case);
Opts.WarnOnEditorPlaceholder |= Args.hasArg(OPT_warn_on_editor_placeholder);

if (auto A = Args.getLastArg(OPT_disable_typo_correction,
Expand Down
4 changes: 1 addition & 3 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4468,11 +4468,9 @@ TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D) {
// An enum element with an associated value cannot be potentially
// unavailable.
if (EED->hasAssociatedValues()) {
auto &ctx = DC->getASTContext();
auto *SF = DC->getParentSourceFile();

if (SF->Kind == SourceFileKind::Interface ||
ctx.LangOpts.WarnOnPotentiallyUnavailableEnumCase) {
if (SF->Kind == SourceFileKind::Interface) {
return diag::availability_enum_element_no_potential_warn;
} else {
return diag::availability_enum_element_no_potential;
Expand Down
2 changes: 1 addition & 1 deletion test/Sema/Inputs/availability_enum_case_other.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public enum Horse {
@available(macOS 100, *)
@available(macOS 10.50, *)
case kevin(Int)
}
6 changes: 3 additions & 3 deletions test/Sema/availability_enum_case.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// RUN: %empty-directory(%t)

// RUN: %target-build-swift -emit-module %S/Inputs/availability_enum_case_other.swift -emit-module-interface-path %t/availability_enum_case_other.swiftinterface -swift-version 5 -enable-library-evolution
// RUN: %target-build-swift -emit-module %S/Inputs/availability_enum_case_other.swift -target %target-cpu-apple-macosx10.50 -emit-module-interface-path %t/availability_enum_case_other.swiftinterface -swift-version 5 -enable-library-evolution
// RUN: %target-typecheck-verify-swift -I %t

// RUN: %target-build-swift -emit-module %S/Inputs/availability_enum_case_other.swift -emit-module-interface-path %t/availability_enum_case_other.swiftinterface -swift-version 5 -enable-library-evolution -whole-module-optimization
// RUN: %target-build-swift -emit-module %S/Inputs/availability_enum_case_other.swift -target %target-cpu-apple-macosx10.50 -emit-module-interface-path %t/availability_enum_case_other.swiftinterface -swift-version 5 -enable-library-evolution -whole-module-optimization
// RUN: %target-typecheck-verify-swift -I %t

// REQUIRES: OS=macosx
Expand All @@ -14,6 +14,6 @@ func ride(horse: Horse) {
// expected-note@-1 {{add @available attribute to enclosing global function}}

_ = Horse.kevin
// expected-error@-1 {{'kevin' is only available in macOS 100 or newer}}
// expected-error@-1 {{'kevin' is only available in macOS 10.50 or newer}}
// expected-note@-2 {{add 'if #available' version check}}
}