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-7449] Conditional conformances: Execute extension function with wrong type #49992

Closed
swift-ci opened this issue Apr 17, 2018 · 4 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself conditional conformances Feature → protocol → conformances: conditional conformances

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7449
Radar rdar://problem/39492423
Original Reporter tarunon (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode Version 9.3 (9E145)
Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Target: x86_64-apple-darwin17.5.0

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

md5: f5969e1fb4d1fd509d68980e7803ceef

Issue Description:

protocol A {
    static func foo()
}

extension Dictionary: A where Key == Value {
    static func foo() {
        print(type(of: self))
    }
}

extension Array where Element: A {
    static func foo() {
        Element.foo()
    }
}

[String: String].foo() // Dictionary<String, String>
[[String: String]].foo() // Dictionary<Dictionary<String, String>, Dictionary<String, String>>

1. Make conditional conformance with equivement 2 generics parameter.
2. Extend other generics parameter while the protocol that used on [1.]

@swift-ci
Copy link
Collaborator Author

Comment by Taketo Sano (JIRA)

I suspect this is the same cause of the EXC_BAD_ACCESS problem I was suffering from. (currently commented out)

https://github.com/taketo1024/SwiftyMath/blob/master/Sources/SwiftyMath/Abstract/Map.swift#L58

@belkadan
Copy link
Contributor

Yikes! Thanks, Nobuo.

@swift-ci create

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 24, 2018

Element is the correct type, but it's being passed off strangely to foo.

protocol A {
    static func foo()
}
func callFoo<T: A>(_: T.Type) {
    print("** callfoo")
    print(T.self)
    T.foo()
}

extension Dictionary: A where Key == Value {
    static func foo() {
        print("** Dictionary.foo")
        print(type(of: self))
    }
}

extension Array where Element: A {
    static func foo() {
        print("** Array.foo")
        print(type(of: self))
        print(Element.self)
        Element.foo()
        callFoo(Element.self)
    }
}

[String: String].foo()
[[String: String]].foo()
** Dictionary.foo
Dictionary<String, String>.Type
** Array.foo
Array<Dictionary<String, String>>.Type
Dictionary<String, String>
** Dictionary.foo
Dictionary<Dictionary<String, String>, Dictionary<String, String>>.Type
** callfoo
Dictionary<String, String>
** Dictionary.foo
Dictionary<Dictionary<String, String>, Dictionary<String, String>>.Type

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 27, 2018

This was fixed by #15960

@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 conditional conformances Feature → protocol → conformances: conditional conformances
Projects
None yet
Development

No branches or pull requests

2 participants