Skip to content
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
5 changes: 5 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -6528,6 +6528,11 @@ ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
none, "Can not use feature when experimental move only is disabled! Pass"
" the frontend flag -enable-experimental-move-only to swift to enable "
"the usage of this language feature", ())
ERROR(experimental_moveonly_feature_can_only_be_imported_when_enabled,
none, "Can not import module %0 that uses move only features when "
"experimental move only is disabled! Pass the frontend flag "
"-enable-experimental-move-only to swift to enable the usage of this "
"language feature", (Identifier))
ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
none, "'@_noImplicitCopy' attribute can only be applied to local lets and params", ())
ERROR(noimplicitcopy_attr_invalid_in_generic_context,
Expand Down
18 changes: 15 additions & 3 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ModuleFormat.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/Attr.h"
#include "swift/AST/AttrKind.h"
#include "swift/AST/AutoDiff.h"
#include "swift/AST/DiagnosticsSema.h"
#include "swift/AST/Expr.h"
Expand All @@ -24,18 +25,18 @@
#include "swift/AST/GenericEnvironment.h"
#include "swift/AST/Initializer.h"
#include "swift/AST/NameLookupRequests.h"
#include "swift/AST/Pattern.h"
#include "swift/AST/ParameterList.h"
#include "swift/AST/Pattern.h"
#include "swift/AST/PrettyStackTrace.h"
#include "swift/AST/PropertyWrappers.h"
#include "swift/AST/ProtocolConformance.h"
#include "swift/AST/TypeCheckRequests.h"
#include "swift/Basic/Defer.h"
#include "swift/Basic/Statistic.h"
#include "swift/ClangImporter/ClangImporter.h"
#include "swift/ClangImporter/ClangModule.h"
#include "swift/ClangImporter/SwiftAbstractBasicReader.h"
#include "swift/Serialization/SerializedModuleLoader.h"
#include "swift/Basic/Defer.h"
#include "swift/Basic/Statistic.h"
#include "clang/AST/DeclTemplate.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/Compiler.h"
Expand Down Expand Up @@ -5131,6 +5132,17 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
MF.fatal(llvm::make_error<InvalidRecordKindError>(recordID));
}

// Do a quick check to see if this attribute is a move only attribute. If
// so, emit a nice error if we don't have experimental move only enabled.
if (Attr->getKind() == DeclAttrKind::DAK_MoveOnly &&
!MF.getContext().LangOpts.Features.contains(Feature::MoveOnly)) {
MF.getContext().Diags.diagnose(
SourceLoc(),
diag::
experimental_moveonly_feature_can_only_be_imported_when_enabled,
MF.getAssociatedModule()->getName());
}

if (!skipAttr) {
if (!Attr)
return llvm::Error::success();
Expand Down
3 changes: 3 additions & 0 deletions test/Serialization/Inputs/moveonly_klass.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

@_moveOnly
public class Klass {}
13 changes: 13 additions & 0 deletions test/Serialization/moveonly.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/Library.swiftmodule -module-name Library %S/Inputs/moveonly_klass.swift -enable-experimental-move-only
// RUN: not %target-swift-frontend -I %t %s -emit-sil -o /dev/null 2>&1 | %FileCheck %s

// This test makes sure that if we import a move only type and do not set the
// experimental move only flag, we get a nice error.

import Library

// CHECK: error: Can not import module 'Library' that uses move only features when experimental move only is disabled! Pass the frontend flag -enable-experimental-move-only to swift to enable the usage of this language feature

func f(_ k: Klass) {
}