Skip to content

Disable diagnostics about problem NSCoding-conforming classes for now. #9808

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
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: 3 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ namespace swift {
/// of Swift do not.
Swift3ObjCInferenceWarnings WarnSwift3ObjCInference =
Swift3ObjCInferenceWarnings::None;

/// Diagnose uses of NSCoding with classes that have unstable mangled names.
bool EnableNSKeyedArchiverDiagnostics = false;

/// Enable keypath components that aren't fully implemented.
bool EnableExperimentalKeyPathComponents = false;
Expand Down
7 changes: 7 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ def disable_swift3_objc_inference :
Flags<[FrontendOption, HelpHidden]>,
HelpText<"Disable Swift 3's @objc inference rules for NSObject-derived classes and 'dynamic' members (emulates Swift 4 behavior)">;

def enable_nskeyedarchiver_diagnostics :
Flag<["-"], "enable-nskeyedarchiver-diagnostics">,
HelpText<"Diagnose classes with unstable mangled names adopting NSCoding">;
def disable_nskeyedarchiver_diagnostics :
Flag<["-"], "disable-nskeyedarchiver-diagnostics">,
HelpText<"Allow classes with unstable mangled names to adopt NSCoding">;

def warn_long_function_bodies : Separate<["-"], "warn-long-function-bodies">,
MetaVarName<"<n>">,
HelpText<"Warns when type-checking a function takes longer than <n> ms">;
Expand Down
5 changes: 5 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,11 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
}
}

Opts.EnableNSKeyedArchiverDiagnostics =
Args.hasFlag(OPT_enable_nskeyedarchiver_diagnostics,
OPT_disable_nskeyedarchiver_diagnostics,
Opts.EnableNSKeyedArchiverDiagnostics);

llvm::Triple Target = Opts.Target;
StringRef TargetArg;
if (const Arg *A = Args.getLastArg(OPT_target)) {
Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6058,7 +6058,8 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
}
}

if (kind && !hasExplicitObjCName(classDecl) &&
if (kind && getLangOpts().EnableNSKeyedArchiverDiagnostics &&
!hasExplicitObjCName(classDecl) &&
!classDecl->getAttrs().hasAttribute<NSKeyedArchiverClassNameAttr>() &&
!classDecl->getAttrs()
.hasAttribute<NSKeyedArchiverEncodeNonGenericSubclassesOnlyAttr>()) {
Expand Down
6 changes: 5 additions & 1 deletion test/decl/protocol/conforms/nscoding.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -verify
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -enable-nskeyedarchiver-diagnostics -verify
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s 2>&1 | %FileCheck -check-prefix CHECK-NO-DIAGS %s

// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -dump-ast 2> %t.ast
// RUN: %FileCheck %s < %t.ast

// REQUIRES: objc_interop

// CHECK-NO-DIAGS-NOT: NSCoding
// CHECK-NO-DIAGS-NOT: unstable

import Foundation

// Top-level classes
Expand Down