Skip to content

Incorrect swift syntax in Generics.rst#default-implementations #62254

@yamagranat

Description

@yamagranat

Description

https://github.com/apple/swift/blob/main/docs/Generics.rst#default-implementations
shows example of protocol providing default implemntations:

protocol Numeric {  
  func +(lhs : Self, rhs : Self) -> Self  
  func -(lhs : Self, rhs : Self) -> Self { return lhs + -rhs }  
  func +(x : Self) -> Self { return x }  
  func -(x : Self) -> Self  
}

but it's not actual implementation of such functionality.
I suppose that the following is better because it shows actual Swift syntax:

protocol Numeric {
  func +(lhs : Self, rhs : Self) -> Self
  func -(x : Self) -> Self
}
extension Numeric {
  func -(lhs : Self, rhs : Self) -> Self { return lhs + -rhs }
  func +(x : Self) -> Self { return x }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationgenericsFeature: generic declarations and typesinaccurate infoBug → documentation: Inaccurate info

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions