You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling parent class's method with return type Self is expected to return type Self. However, calling the method using 'super.methodName' returns the parent class's type instead of Self.
classParentWallet {
varmoney: Intrequiredinit(money: Int) {
self.money = money
}
funcnewWalletWithMoreMoney(_moreMoney: Int) -> Self {
letmoneyForNewWallet = money + moreMoneyreturntype(of:self).init(money: moneyForNewWallet )
}
}
classChildWallet: ParentWallet {
requiredinit(money: Int) {
super.init(money: money)
}
overridefuncnewWalletWithMoreMoney(_moreMoney: Int) -> Self {
letnewWallet = super.newWalletWithMoreMoney(moreMoney) // newWallet has type ParentWallet instead of SelfreturnnewWallet// Error: Cannot convert return expression of type 'ParentWallet' to return type 'Self'
}
}
Without the override function in ChildWallet class, these are sample behaviors:
// wallet1 has type ParentWalletletwallet1 = ParentWallet(money: 10).newWalletWithMoreMoney(5)
// wallet2 has type ChildWalletletwallet2 = ChildWallet(money: 10).newWalletWithMoreMoney(5)
The text was updated successfully, but these errors were encountered:
Environment
Xcode Version 9.1 (9B55)
Swift 4.0
Additional Detail from JIRA
md5: 5a7173bd581ca6612eb55c17a3d359c7
Issue Description:
Calling parent class's method with return type Self is expected to return type Self. However, calling the method using 'super.methodName' returns the parent class's type instead of Self.
Without the override function in ChildWallet class, these are sample behaviors:
The text was updated successfully, but these errors were encountered: