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-10193] Reference to invalid type alias #52593

Closed
DevAndArtist mannequin opened this issue Mar 27, 2019 · 5 comments
Closed

[SR-10193] Reference to invalid type alias #52593

DevAndArtist mannequin opened this issue Mar 27, 2019 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@DevAndArtist
Copy link
Mannequin

DevAndArtist mannequin commented Mar 27, 2019

Previous ID SR-10193
Radar None
Original Reporter @DevAndArtist
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 10.2

Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)

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

md5: 266d9124f3754d31c23c6efca227f889

Issue Description:

typealias PartialKeyPathSet<Root> = Set<PartialKeyPath<Root>>

protocol _Drivable: AnyObject {}

extension _Drivable {
  typealias Driver = GenericDriver<Self>
  var driver: GenericDriver<Self> {
    get { return GenericDriver<Self>(driving: self) }
    set { /* no-op to allow mutation */ }
  }
}

struct GenericDriver<Drivable> {
  let __drivable: Drivable
  init(driving drivable: Drivable) {
    self.__drivable = drivable
  }
}

protocol Configurator {
  associatedtype Drivable: _Drivable
  typealias Driver = Drivable.Driver
  typealias DriverKeyPathSet = PartialKeyPathSet<Driver>
  func configure(_ driver: inout Driver, using set: DriverKeyPathSet)
}

struct AnyConfigurator<Drivable: _Drivable>: Configurator {
  private let _base: Any
  private let _function: (inout Driver, DriverKeyPathSet) -> Void

  init<Other>(_ other: Other)
    where
    Other: Configurator,
    Other.Drivable == Drivable
  {
    _base = other
    _function = other.configure(_:using:)
  }

  // error: Reference to invalid type alias 'Driver' of type 'AnyConfigurator<Drivable>'
  func configure(_ driver: inout Driver, using set: DriverKeyPathSet) {
    _function(&driver, set)
  }
}

The type alias work for `_function` but it's mismatched for the implementation of the protocol requirement.

I assume this to compile the following relation `AnyConfigurator<Drivable>.Driver == Drivable.Driver == GenericDriver<Drivable>`.

Forums discussion: https://forums.swift.org/t/reference-to-invalid-type-alias-is-this-a-bug/22201

@belkadan
Copy link
Contributor

[tweaked code to not require UIKit]

@slavapestov, any insights?

@swift-ci
Copy link
Collaborator

Comment by Garth Snyder (JIRA)

Simplified version:

protocol _Drivable: AnyObject {
    typealias Driver = Self
}
protocol Configurator {
    associatedtype Drivable: _Drivable
    typealias Driver = Drivable.Driver
    func configure(driver: Driver)
}
struct AnyConfigurator<Drivable: _Drivable>: Configurator {
    private let thing: Driver?
    // error: Reference to invalid type alias 'Driver' of type 'AnyConfigurator<Drivable>'
    func configure(driver: Driver) {}
}

@swift-ci
Copy link
Collaborator

Comment by Zhu Shengqi (JIRA)

@slavapestov I have met a problem (warning not error), which may relate to this issue:

public protocol Observable {
  
  associatedtype Element
  
  associatedtype Failure: Error
  
  // warning: Neither type in same-type constraint ('Result<O.Element, O.Failure>' or 'Result<Self.Element, Self.Failure>') refers to a generic parameter or associated type
  func subscribe<O: Observable>(with observer: O) where O.ResultType == ResultType
  
}
 
extension Observable {
  
  public typealias ResultType = Result<Element, Failure>
  
}

@slavapestov
Copy link
Member

#28157

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@tarbaiev-smg
Copy link

Not sure what happened, but its still reproducible on Xcode 14.3.1.

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

4 participants