Skip to content

[SR-3917] Allow missing witnesses for optional and unavailable requirements. #7886

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
Mar 3, 2017
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: 2 additions & 1 deletion lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,8 @@ struct ASTNodeBase {};

if (auto req = dyn_cast<ValueDecl>(member)) {
if (!normal->hasWitness(req)) {
if (req->getAttrs().isUnavailable(Ctx) &&
if ((req->getAttrs().isUnavailable(Ctx) ||
req->getAttrs().hasAttribute<OptionalAttr>()) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird indentation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got some serious tabs going on, apparently. Will fix!

proto->isObjC()) {
continue;
}
Expand Down
6 changes: 5 additions & 1 deletion lib/AST/ProtocolConformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,11 @@ void NormalProtocolConformance::setWitness(ValueDecl *requirement,
assert(getProtocol() == cast<ProtocolDecl>(requirement->getDeclContext()) &&
"requirement in wrong protocol");
assert(Mapping.count(requirement) == 0 && "Witness already known");
assert((!isComplete() || isInvalid()) && "Conformance already complete?");
assert((!isComplete() || isInvalid()
|| requirement->getAttrs().hasAttribute<OptionalAttr>()
|| requirement->getAttrs().isUnavailable(
requirement->getASTContext())) &&
"Conformance already complete?");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird indentation

Mapping[requirement] = witness;
}

Expand Down
9 changes: 9 additions & 0 deletions test/Serialization/Inputs/def_objc_conforming.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

@objc public protocol Proto {
@objc optional func badness()
}

public class Foo: Proto {
public var badness: Int = 0 // unrelated
}
16 changes: 16 additions & 0 deletions test/Serialization/objc_optional_reqs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: rm -rf %t
// RUN: mkdir -p %t

// FIXME: BEGIN -enable-source-import hackaround
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t %clang-importer-sdk-path/swift-modules/Foundation.swift
// FIXME: END -enable-source-import hackaround

// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -emit-module -o %t %S/Inputs/def_objc_conforming.swift
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -typecheck %s -verify

// REQUIRES: objc_interop

// SR-3917
import def_objc_conforming

func test(x: Foo) { _ = x.badness }