Skip to content

[Sema] Diagnose use of implementation-only property wrappers #30939

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 1 commit into from
Apr 10, 2020
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
4 changes: 2 additions & 2 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -2651,14 +2651,14 @@ NOTE(construct_raw_representable_from_unwrapped_value,none,
"construct %0 from unwrapped %1 value", (Type, Type))

ERROR(decl_from_hidden_module,none,
"cannot use %0 %1 %select{here|"
"cannot use %0 %1 %select{here|as property wrapper here|"
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances}2; "
"%select{%3 has been imported as implementation-only|"
"it is an SPI imported from %3}4",
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
ERROR(conformance_from_implementation_only_module,none,
"cannot use conformance of %0 to %1 %select{here|"
"cannot use conformance of %0 to %1 %select{here|as property wrapper here|"
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances}2; %3 has been imported "
"as implementation-only",
Expand Down
6 changes: 6 additions & 0 deletions lib/Sema/TypeCheckAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
// diag::conformance_from_implementation_only_module.
enum class Reason : unsigned {
General,
PropertyWrapper,
ExtensionWithPublicMembers,
ExtensionWithConditionalConformances
};
Expand Down Expand Up @@ -1836,6 +1837,11 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
return;

checkType(TP->getTypeLoc(), anyVar, getDiagnoser(anyVar));

// Check the property wrapper types.
for (auto attr : anyVar->getAttachedPropertyWrappers())
checkType(attr->getTypeLoc(), anyVar,
getDiagnoser(anyVar, Reason::PropertyWrapper));
}

void visitPatternBindingDecl(PatternBindingDecl *PBD) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ public struct IntLike: ExpressibleByIntegerLiteral, Equatable {
public init(integerLiteral: Int) {}
}

@propertyWrapper
public struct BadWrapper {
public var wrappedValue: Int
public init(wrappedValue: Int) {
self.wrappedValue = wrappedValue
}
}

precedencegroup BadPrecedence {}
4 changes: 4 additions & 0 deletions test/Sema/implementation-only-import-in-decls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public struct TestInit {
public init<T>(where _: T) where T: BadProto {} // expected-error {{cannot use protocol 'BadProto' here; 'BADLibrary' has been imported as implementation-only}}
}

public struct TestPropertyWrapper {
@BadWrapper public var BadProperty: Int // expected-error {{cannot use struct 'BadWrapper' as property wrapper here; 'BADLibrary' has been imported as implementation-only}}
}

public protocol TestInherited: BadProto {} // expected-error {{cannot use protocol 'BadProto' here; 'BADLibrary' has been imported as implementation-only}}

public protocol TestConstraintBase {
Expand Down
5 changes: 2 additions & 3 deletions test/Serialization/Recovery/implementation-only-missing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public struct PublicStruct: LibProtocol {

public init() { }

@IoiPropertyWrapper("some text")
public var wrappedVar: String
public var nonWrappedVar: String = "some text"
}

struct StructWithOverride: HiddenProtocolWithOverride {
Expand All @@ -87,6 +86,6 @@ struct StructWithOverride: HiddenProtocolWithOverride {
import public_lib

var s = PublicStruct()
print(s.wrappedVar)
print(s.nonWrappedVar)

#endif