Non-final method that returns opaque result type is allowed

According to the proposal, non final method that returns opaque result type is not allowed now.

Similarly to the restriction on protocols, opaque result types cannot be used for a non-final declaration within a class:

class C {
 func f() -> some P { /* ... */ } // error: cannot use opaque result type with a non-final method
 final func g() -> some P { /* ... */ } // ok

This restriction could conceivably be lifted in the future, but it would mean that override implementations would be constrained to returning the same type as their super implementation, meaning they must call super.method() to produce a valid return value.

However, with Swift5.5, this code works fine.

class C {
    func f() -> some Numeric { 42 }       // ok
    final func g() -> some Numeric { 42 } // ok

However, override of f is impossible even if I use super.f().

class D: C {
    // Error: Method does not override any method from its superclass
    override func f() -> some Numeric {
        return super.f()

Is the limitation has been lifted? Or is this an unexpected behavior?

Terms of Service

Privacy Policy

Cookie Policy