Skip to content

Instantly share code, notes, and snippets.

@tarunon
Created February 17, 2017 15:10
Show Gist options
  • Save tarunon/d7071689ab55e29bd367a44833687aa3 to your computer and use it in GitHub Desktop.
Save tarunon/d7071689ab55e29bd367a44833687aa3 to your computer and use it in GitHub Desktop.
protocol A {
associatedtype X
func hoge(_ arg: X)
}
extension A where X == Void {
func hoge(_ arg: Void) {
}
}
class B: A {
}
@tarunon
Copy link
Author

tarunon commented Feb 17, 2017

where句を無視して全ての型にfunc hoge(_ arg:Void)が生えていると仮定することでB.X==Voidが決定できるのではないか説 by @ezura

@ezura
Copy link

ezura commented Feb 17, 2017

スコープ区切ってあげると where句完全無視説が崩れそう(´・ω・`)?

// file1.swift
protocol A {
    associatedtype X
    func hoge(_ arg: X)
}

extension A /* where X == Void */ {
    func hoge(_ arg: Void) {
        
    }
}

class B: A {}
// file2.swift
private protocol P {}

extension A where Self: P {
    func hoge(_ arg: Int) {
        print(#function, #line)
    }
}

private struct C: A, P {
}

@tarunon
Copy link
Author

tarunon commented Feb 17, 2017

デフォルト実装が増えた場合は死ぬだろうと予想してましたが、ファイルを分割すれば通る…ウーン…

@tarunon
Copy link
Author

tarunon commented Feb 17, 2017

でもこれX==Voidを起こすとCは死にますね

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment