Skip to content

Commit cb1a5b2

Browse files
mpvlcueckoo
authored andcommitted
doc/ref/spec.md: support comparing values of different types
This means == (and != accordingly) will return false, instead of an error, when comparing two different values of different types. Issue #2583 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Ia967ed235222bd3b50f0dee59da56e7e38b5b551 Dispatch-Trailer: {"type":"trybot","CL":1217013,"patchset":12,"ref":"refs/changes/13/1217013/12","targetBranch":"master"}
1 parent 4dd8a07 commit cb1a5b2

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

doc/ref/spec.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ An _atom_ is any value whose only instances are itself and bottom.
586586
Examples of atoms are `42.0`, `"hello"`, `true`, and `null`.
587587

588588
A value is _concrete_ if it is either an atom, or a struct whose field values
589-
are all concrete, recursively.
589+
of regular (non-hidden and non-definition fields) are all concrete, recursively.
590590

591591
CUE's values also include what we normally think of as types, like `string` and
592592
`float`.
@@ -2324,7 +2324,7 @@ s: "etc. "*3 // "etc. etc. etc. "
23242324

23252325
##### Comparison operators
23262326

2327-
Comparison operators compare two operands and yield an untyped boolean value.
2327+
Comparison operators compare two concrete operands and yield a boolean value.
23282328

23292329
```
23302330
== equal
@@ -2339,24 +2339,25 @@ Comparison operators compare two operands and yield an untyped boolean value.
23392339

23402340
<!-- regular expression operator inspired by Bash, Perl, and Ruby. -->
23412341

2342-
In any comparison, the types of the two operands must unify or one of the
2343-
operands must be null.
2342+
In any comparison, both operands must be concrete; otherwise the result is
2343+
bottom (`_|_`).
23442344

2345-
The equality operators `==` and `!=` apply to operands that are comparable.
2346-
The ordering operators `<`, `<=`, `>`, and `>=` apply to operands that are ordered.
2345+
If two operands are not comparable with each other, the result is false for `==`
2346+
and true for `!=`.
2347+
The ordering operators `<`, `<=`, `>`, and `>=` apply to operands for which
2348+
an ordering is defined.
23472349
The matching operators `=~` and `!~` apply to a string and a regular
23482350
expression operand.
23492351
These terms and the result of the comparisons are defined as follows:
23502352

2351-
- Null is comparable with itself and any other type.
2352-
Two null values are always equal, null is unequal with anything else.
2353+
- Null is comparable and equal to itself only.
23532354
- Boolean values are comparable.
23542355
Two boolean values are equal if they are either both true or both false.
23552356
- Integer values are comparable and ordered, in the usual way.
23562357
- Floating-point values are comparable and ordered, as per the definitions
23572358
for binary coded decimals in the IEEE-754-2008 standard.
2358-
- Floating-point numbers may be compared with integers; the comparison is
2359-
performed as if the integer was first converted to a floating-point number.
2359+
- Floating-point numbers are comparable and ordered with respect to integers
2360+
by first converting the integer to a floating-point value.
23602361
- String and bytes values are comparable and ordered lexically byte-wise.
23612362
- Structs are comparable but not ordered. Two structs are equal if they have the
23622363
same set of regular field labels and the corresponding values are recursively

0 commit comments

Comments
 (0)