A question about use 'lowerThan' in 'precedencegroup', maybe is a bug

What you are reading from is not documentation of how to use Swift at present, but rather leftover documents from its design process. They are retained for historical purposes, but are not updated to match any changes that have been made to the language since.

For up‐to‐date documentation, look on the Swift or Apple websites instead of in the Swift Evolution repository.

Since that document was written, these had their names changed to RangeFormationPrecedence, AdditionPrecedence, MultiplicationPrecedence and ComparisonPrecedence.

The comment was meant to indicate that these lines would be part of the standard library included with Swift itself. You were not expected to copy and paste them into your own file.

This part labelled “module A” is what would belong in your own code if you wanted it. It should still work, as long as you update Comparative to ComparisonPrecedence

Once the two separate halves of the example are placed where they were intended to be, then Equivalence is indeed in a separate module as the comment describes.

Always preferring higherThan reduces the odds of circularity mistakes. Within one module you control both declarations, and so it is simplest to declare all relationships using higherThan.

When you refer to a precedence group from another module, you do not necessarily have access to its code, and may be unable to alter it. So for that type of relationship, lowerThan is allowed so that you can describe the relationship from within your own module’s code.

(If you are not already familiar with what a module is, see here and here.)

This is illegal, unless the argument to lowerThan is from another module (i.e. coming from an import statement).

1 Like