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-12736] cannot add constraint 'Self.Model.Float32Components == Self.Model.Float32Components.Model.Float32Components' on 'Self' #55182

Closed
SusanDoggie opened this issue May 5, 2020 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@SusanDoggie
Copy link
Contributor

Previous ID SR-12736
Radar rdar://problem/62894047
Original Reporter @SusanDoggie
Type Bug
Status Resolved
Resolution Done
Environment

swift 5.1
swift 5.2.3
Xcode 11.4.1

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

md5: 81036c9f59b1c54443089757184cc9ce

Issue Description:

The following code will produce a compilation error, but it should not happen.

public protocol ColorModel {
    
    associatedtype Float32Components: ColorComponents where Float32Components.Model == Self, Float32Components.Scalar == Float
    
    init<T: ColorComponents>(_ components: T) where T.Model == Self
    
    var float32Components: Float32Components { get set }
}

public protocol ColorComponents {
    
    associatedtype Model: ColorModel
    
    associatedtype Scalar
    
}

public protocol ColorPixel {
    
    associatedtype Model: ColorModel
    
    init(color: Model, opacity: Double)
    
    init<C: ColorPixel>(_ color: C) where C.Model == Model
}
@beccadax
Copy link
Contributor

beccadax commented May 5, 2020

@swift-ci create

@typesanitizer
Copy link

Seems like a declaration type-checking bug. If I minimize the example:

protocol P1 {
    associatedtype AT1: P2 where AT1.AT2 == Self
}

protocol P2 {
    associatedtype AT2: P1
}

protocol P3 {
    associatedtype AT3: P1
    init<T: P3>(_ t: T) where T.AT3 == AT3 // error: initializer requirement 'init(_:)' cannot add constraint 'Self.AT3.AT1 == Self.AT3.AT1.AT2.AT1' on 'Self'
}

On the other hand, if you add the initializer to an extension with a default implementation, that's fine.

protocol P1 {
    associatedtype AT1: P2 where AT1.AT2 == Self
}

protocol P2 {
    associatedtype AT2: P1
}

protocol P3 {
    associatedtype AT3: P1
}

extension P3 {
    init<T: P3>(_ t: T) where T.AT3 == AT3 {
        fatalError("AAAAA")
    }
}

@SusanDoggie
Copy link
Contributor Author

I think this bug maybe related to SR-10532

@CodaFi
Copy link
Member

CodaFi commented May 11, 2020

The order of constraints matters, though why I'm not quite sure as yet. This compiles:

public protocol ColorModel {
    
    associatedtype Float32Components: ColorComponents where Float32Components.Model == Self, Float32Components.Scalar == Float
    
    init<T: ColorComponents>(_ components: T) where T.Model == Self
    
    var float32Components: Float32Components { get set }
}

public protocol ColorComponents {
    
    associatedtype Model: ColorModel
    
    associatedtype Scalar
    
}

public protocol ColorPixel {
    
    associatedtype Model: ColorModel
    
    init(color: Model, opacity: Double)
    
    init<C: ColorPixel>(_ color: C) where Self.Model == C.Model
}

@slavapestov
Copy link
Member

#42113

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

5 participants