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

[SR-6433] Cannot declare public default protocol impls based on shadowed associated types #48983

Closed
karwa opened this issue Nov 18, 2017 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@karwa
Copy link
Contributor

karwa commented Nov 18, 2017

Previous ID SR-6433
Radar None
Original Reporter @karwa
Type Bug
Status Resolved
Resolution Duplicate
Environment

Version 9.2 beta (9C32c)

Apple Swift version 4.0.3 (swiftlang-900.0.71 clang-900.0.38)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 73935e9dc5ce6ff220d1e7eebbe68006

duplicates:

  • SR-2925 Inconsistent linking in debug vs. release builds w/ public method in extension of internal protocol

Issue Description:

I have a library, exposing a public protocol (MapController below). I'm using a refined, internal protocol to avoid writing boilerplate for wrappers of the base.

I want to set a default for some of the inherited associated types. The only way to do that seems to be to redeclare them in the refined protocol with a default. However, this stops me writing public default implementations based on constraints using that inherited associated type.

public struct Observable<T> {}
public enum Geo { public struct Rect {} }

public protocol MapController: class {
  associatedtype PlaceType
  associatedtype OptionsType

  var places: Observable<[PlaceType]> { get }

  var region: Geo.Rect { get set }
  var options: OptionsType { get set }
  func setRegion(_ newRegion: Geo.Rect, options: OptionsType)
}

protocol MapControllerWrapper: MapController {
  associatedtype Wrapped: MapController
  associatedtype OptionsType = Wrapped.OptionsType

  var base: Wrapped { get }
}

// This default implementation seems to work. Note it is declared 'public'.

extension MapControllerWrapper {
  public var region: Geo.Rect {
    get { return base.region }
    set { base.region = newValue }
  }
}

// This one doesn't.
// "Cannot declare a public var in an extension with internal requirements".

extension MapControllerWrapper where OptionsType == Wrapped.OptionsType {
  public var options: OptionsType {
    get { return base.options }
    set { base.options = newValue }
  }
  public func setRegion(_ newRegion: Geo.Rect, options: OptionsType) {
    base.setRegion(newRegion, options: options)
  }
}
@belkadan
Copy link
Contributor

This is not supported today. It might look like it is because of SE-0025, but the public in the unconstrained extension is supposed to be ignored today. (It might not be, but that's a bug that can lead to linker errors.)

(In theory this could also apply to the constrained extension, but that's closer to "a function cannot be made public if it has non-public arguments".)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants