Skip to content
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

Allow Deriving Type Witnesses Across Files #33187

Merged
merged 1 commit into from
Jul 30, 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
3 changes: 0 additions & 3 deletions lib/Sema/DerivedConformanceCaseIterable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ ValueDecl *DerivedConformance::deriveCaseIterable(ValueDecl *requirement) {
}

Type DerivedConformance::deriveCaseIterable(AssociatedTypeDecl *assocType) {
if (checkAndDiagnoseDisallowedContext(assocType))
return nullptr;

// Check that we can actually derive CaseIterable for this type.
if (!canDeriveConformance(Nominal))
return nullptr;
Expand Down
3 changes: 0 additions & 3 deletions lib/Sema/DerivedConformanceDifferentiable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,6 @@ DerivedConformance::deriveDifferentiable(AssociatedTypeDecl *requirement) {
diag::broken_differentiable_requirement);
return std::make_pair(nullptr, nullptr);
}
// Diagnose conformances in disallowed contexts.
if (checkAndDiagnoseDisallowedContext(requirement))
return std::make_pair(nullptr, nullptr);

// Start an error diagnostic before attempting derivation.
// If derivation succeeds, cancel the diagnostic.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import _Differentiation

// expected-note @+1 {{type declared here}}
// expected-note @+1 2 {{type declared here}}
class OtherFileNonconforming {}

// expected-note @+1 {{type declared here}}
// expected-note @+1 2 {{type declared here}}
class GenericOtherFileNonconforming<T: Differentiable> {
var x: T
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import _Differentiation

// expected-note @+1 {{type declared here}}
// expected-note @+1 2 {{type declared here}}
struct OtherFileNonconforming {}

// expected-note @+1 {{type declared here}}
// expected-note @+1 2 {{type declared here}}
struct GenericOtherFileNonconforming<T: Differentiable> {
var x: T
}
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,8 @@ class WrappedProperties: Differentiable {

// Test derived conformances in disallowed contexts.

// expected-error @+2 {{type 'OtherFileNonconforming' does not conform to protocol 'Differentiable'}}
// expected-error @+1 {{implementation of 'Differentiable' cannot be automatically synthesized in an extension in a different file to the type}}
// expected-error @+1 2 {{implementation of 'Differentiable' cannot be automatically synthesized in an extension in a different file to the type}}
extension OtherFileNonconforming: Differentiable {}

// expected-error @+2 {{type 'GenericOtherFileNonconforming<T>' does not conform to protocol 'Differentiable'}}
// expected-error @+1 {{implementation of 'Differentiable' cannot be automatically synthesized in an extension in a different file to the type}}
// expected-error @+1 2 {{implementation of 'Differentiable' cannot be automatically synthesized in an extension in a different file to the type}}
extension GenericOtherFileNonconforming: Differentiable {}
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,8 @@ struct WrappedProperties: Differentiable {

// Verify that cross-file derived conformances are disallowed.

// expected-error @+2 {{type 'OtherFileNonconforming' does not conform to protocol 'Differentiable'}}
// expected-error @+1 {{implementation of 'Differentiable' cannot be automatically synthesized in an extension in a different file to the type}}
// expected-error @+1 2 {{implementation of 'Differentiable' cannot be automatically synthesized in an extension in a different file to the type}}
extension OtherFileNonconforming: Differentiable {}

// expected-error @+2 {{type 'GenericOtherFileNonconforming<T>' does not conform to protocol 'Differentiable'}}
// expected-error @+1 {{implementation of 'Differentiable' cannot be automatically synthesized in an extension in a different file to the type}}
// expected-error @+1 2 {{implementation of 'Differentiable' cannot be automatically synthesized in an extension in a different file to the type}}
extension GenericOtherFileNonconforming: Differentiable {}
4 changes: 4 additions & 0 deletions test/Sema/Inputs/enum_conformance_synthesis_other.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ extension ImpliedMain: ImplierMain {}
enum ImpliedOther: ImplierOther {
case a(Int)
}

enum CaseIterableAcrossFiles {
case A
}
7 changes: 6 additions & 1 deletion test/Sema/enum_conformance_synthesis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ enum Complex2 {
}
extension Complex2 : Hashable {}
extension Complex2 : CaseIterable {} // expected-error {{type 'Complex2' does not conform to protocol 'CaseIterable'}}
extension FromOtherFile: CaseIterable {} // expected-error {{cannot be automatically synthesized in an extension in a different file to the type}} expected-error {{does not conform to protocol 'CaseIterable'}}
extension FromOtherFile: CaseIterable {} // expected-error {{cannot be automatically synthesized in an extension in a different file to the type}}
extension CaseIterableAcrossFiles: CaseIterable {
public static var allCases: [CaseIterableAcrossFiles] {
return [ .A ]
}
}

// No explicit conformance and it cannot be derived.
enum NotExplicitlyHashableAndCannotDerive {
Expand Down