[swift-evolution] Calling a Specific Implementation

Ben Rimmington me at benrimmington.com
Thu Aug 18 22:21:42 CDT 2016


> On 18 Aug 2016, at 16:32, John McCall <rjmccall at apple.com> wrote:
> 
> Unapplied method references still dispatch down.  It's a pretty simple experiment to run for yourself.

When I tried calling a specific superclass implementation, there was a stack overflow due to the infinite recursion.

	class Once {
	    func value() -> Int {
	        return 1
	    }
	}

	class Twice: Once {
	    override func value() -> Int {
	        return 2
	    }
	}

	class Thrice: Twice {
	    override func value() -> Int {
	        return 3

	        // EXC_BAD_ACCESS:
	        // return Once.value(self)()
	    }
	}

	let once = Once()
	once.value()            //-> 1
	Once.value(once)()      //-> 1

	let twice = Twice()
	twice.value()           //-> 2
	Once.value(twice)()     //-> 2
	Twice.value(twice)()    //-> 2

	let thrice = Thrice()
	thrice.value()          //-> 3
	Once.value(thrice)()    //-> 3
	Twice.value(thrice)()   //-> 3
	Thrice.value(thrice)()  //-> 3

-- Ben



More information about the swift-evolution mailing list