> On Apr 24, 2016, at 7:57 PM, Brent Royal-Gordon via swift-evolution
> <[email protected]> wrote:
>
>>
>> https://github.com/apple/swift-evolution/blob/master/proposals/0068-universal-self.md
>
> I'm not totally clear what's being proposed here.
>
> Is this valid?
>
> class Foo {
> static func bar() { … }
> func baz(other: Foo) {
> Self.bar()
> }
> }
This is valid. Foo.bar().
>
> Is this valid?
>
> struct Foo { // note: not class
> static func bar() { … }
> func baz(other: Foo) {
> Self.bar()
> }
> }
>
This is valid. Foo.bar()
> Is this valid?
>
> class Foo {
> static func bar() { … }
> func baz(other: Foo) {
> other.Self.bar() // note: not self
> }
> }
>
This is valid. Foo.bar(). All instances of the class share the static bar()
member.
> Is this valid?
>
> struct Foo { // note: not class
> static func bar() { … }
> func baz(other: Foo) {
> other.Self.bar() // note: not self
> }
> }
>
This is should be valid although it currently errors with `dynamicType` (error:
type 'Foo' has no member 'bar').
You missed subclassing, although being static members, methods are final and
cannot be overridden. But if class Boo : Foo calls Self.bar() and Foo
implements the static member, it's called from the Boo instance and uses the
Foo implementation.
> Can a class have a variable (inside a method) of type Self? A return value? A
> parameter? A property?
I think it should, however that technically may need to be of type #Self (per
the original draft) instead of Self and have it expanded to the defining type
at compile time.
> Can a value type have a variable (inside a method) of type Self? A return
> value? A parameter? A property?
Ditto.
-- E
>
> --
> Brent Royal-Gordon
> Architechies
>
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution