Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Operators are not included in the generated documentation if there are multiple operators with the same name #263

Open
Lukas-Stuehrk opened this issue Apr 26, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@Lukas-Stuehrk
Copy link
Member

Lukas-Stuehrk commented Apr 26, 2021

It's possible to use an operator name multiple times and create multiple definitions for an operator with the same name. It can be defined up to three times.

  1. As a prefix operator.
  2. As an infix operator.
  3. As a posfix operator.

For example, the given Swift source (where the operators don't make too much sense, there are better ideas for custom operators out there):

infix operator 

public func  (lhs: String, rhs: String) -> Bool {
    lhs != rhs
}

public func  (lhs: Int, rhs: Int) -> Bool {
    lhs != rhs
}


prefix operator 
public prefix func  (arg: String) -> Bool { false }

will create the following documentation (after the fixes in #262) which is missing the declaration of the infix operator and all the operator implementations of the infix operator:
Screenshot 2021-04-26 at 18 52 40

This is more or less an artifact how Identifier works for operators. It does not differentiate between the different kind of operators, therefore an infix operator has the same identifier as a postfix operator as a prefix operator.

I can see multiple ways how we fix this.

1. Make Identifier have a different Equatable and Hashable for operators and create different OperatorPages for the different kind of operators. Not sure if I like it.
2. Change a little bit the OperatorPage. Currently it works with the assumption that an operator name has exactly one definition. We could collect all different operator definitions (prefix, infix, postfix) on the same page and then group the implementations by definition.

Update: My initial assumption was wrong. It's way more trivial. We already create multiple pages for the different kind of operators, but the last operator declaration always wins because it overwrites the page of the previous declaration:

pages[route(for: symbol)] = operatorPage

@Lukas-Stuehrk Lukas-Stuehrk added the bug Something isn't working label Apr 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant