Skip to content

Add tests for class constrained protocol extension #26696

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
Aug 19, 2019
Merged
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
29 changes: 29 additions & 0 deletions test/decl/ext/extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,32 @@ struct WrapperContext {
static let propUsingMember = originalValue
}
}

// Class-constrained extension where protocol does not impose class requirement

protocol DoesNotImposeClassReq_1 {}

class JustAClass: DoesNotImposeClassReq_1 {
var property: String = ""
}

extension DoesNotImposeClassReq_1 where Self: JustAClass {
var wrappingProperty: String {
get { return property }
set { property = newValue }
}
}

let instanceOfJustAClass = JustAClass() // expected-note {{change 'let' to 'var' to make it mutable}}
instanceOfJustAClass.wrappingProperty = "" // expected-error {{cannot assign to property: 'instanceOfJustAClass' is a 'let' constant}}

protocol DoesNotImposeClassReq_2 {
var property: String { get set }
}

extension DoesNotImposeClassReq_2 where Self : AnyObject {
var wrappingProperty: String {
get { property }
set { property = newValue } // Okay
}
}