length: int- Module
- std.
bytes - Receiver
- Bytes
- Minimum arity
- 0
- Maximum arity
- 0
Declaration and parameters
LinkAvailability
Included by default: Pending
Import std.bytes in language mode 5.21.
The current compiler selects std/bytes.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 954 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 52 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 954 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 410 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1296 - compiler/crates/topaz_value/src/value/members.rs at
b48527d0a174· 248
Receiver
Bytes
Parameter constraints
Bytes.length and ByteBuffer.length are read-only int properties that report the number of bytes.
JSONValue.length is an Option<int> property. Arrays and objects return Some(count) for their element or member count. Other JSON kinds return None().
JSONValue.keys and JSONValue.values are properties returning Option<Array<string>> and Option<Array<JSON. Objects return Some(keys) or Some(values). Other JSON kinds return None().
Read these properties without parentheses, as with Array.length, Map.length, Map.keys, Map.values, and Set.length. Calling a property value is rejected as a non-callable value.
Related rule: Read collection sizes, keys, and values as propertiesTest whether a Bytes, Map, or Set value is empty by comparing its length property with zero. The comparison is true exactly when the collection has no bytes, entries, or elements.
Bytes, Map, and Set do not expose an isEmpty member. Read the length property and use the ordinary equality operator.
Related rule: Test collection emptiness with lengthA Bytes value is an immutable ordered sequence of octets. Each octet is an int from 0 through 255.
Bytes.empty returns the empty sequence. Bytes.fromArray accepts an Array<int> and returns an independent snapshot in Ok.
Bytes.fromArray returns Err with a string identifying the first element outside 0 through 255. It does not wrap, clamp, or return a partial sequence.
Bytes.toArray returns a new Array<int> in byte order. Mutating that array or the original input array does not change an existing Bytes value.
Bytes.concat returns the receiver bytes followed by the argument bytes. Either input may be empty and both inputs retain their contents.
Bytes.get uses a zero-based byte index. It returns Some(byte) within the sequence and None() for every negative or past-end index.
Bytes.length is the number of bytes and is read as a property. Compare it with zero to test emptiness.
Receivers and supplied arguments evaluate once from left to right before the operation begins. These operations perform no I/O or text normalization.
A correctly typed lookup or concatenation has no data-dependent Result failure. Allocation exhaustion is an operational failure and is not a decoded data error.
Related rule: Construct and inspect immutable byte sequencesResult
The declared result type is int.
Effects
Failures
Result and effects
LinkSelect this field from a value of its named type without call parentheses.
Read the number of bytes as a read-only int property. Compare it with zero to test emptiness.
Why
LinkCollection observations use the same property syntax as Array, Map, and Set. Parentheses identify calls rather than stored or derived values.
Related entries
LinkRead collection sizes, keys, and values as properties
LinkRead collection sizes, keys, and values as properties
Bytes.length and ByteBuffer.length are read-only int properties that report the number of bytes.
JSONValue.length is an Option<int> property. Arrays and objects return Some(count) for their element or member count. Other JSON kinds return None().
JSONValue.keys and JSONValue.values are properties returning Option<Array<string>> and Option<Array<JSON. Objects return Some(keys) or Some(values). Other JSON kinds return None().
Read these properties without parentheses, as with Array.length, Map.length, Map.keys, Map.values, and Set.length. Calling a property value is rejected as a non-callable value.
Why
The same collection observation should use the same syntax across core collections and library values. Keeping JSONValue results optional preserves its distinction between collections and scalar values.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Read the same properties on core collections
Linkimport std.iolet array = [2, 3]let entries = map { "name": "Topaz" }let values = set { 2, 3 }io.writeLine("{array.length}:{entries.length}:{values.length}")io.writeLine(entries.keys[0])io.writeLine(entries.values[0])
2:1:2 name Topaz
Expected result
Expected result
Execution completes. Exit code 0.
2:1:2nameTopaz
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Read a byte sequence size
Linkimport std.bytes { Bytes }import std.iolet bytes = Bytes.empty()let size: int = bytes.lengthio.writeLine("{size}")
0
Expected result
Expected result
Execution completes. Exit code 0.
0
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Read a byte buffer size
Linkimport std.bytes { ByteBuffer }import std.iolet buffer = ByteBuffer.allocate(3)let size: int = buffer.lengthio.writeLine("{size}")
3
Expected result
Expected result
Execution completes. Exit code 0.
3
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Read JSON sizes and preserve optional results
Linkimport std.jsonimport std.testimport std.iolet array = test.assertOk(json.parse("[1,2]"))let object = test.assertOk(json.parse("\{\"name\":\"Topaz\"\}"))let scalar = test.assertOk(json.parse("42"))let arraySize: Option<int> = array.lengthlet objectSize: Option<int> = object.lengthlet scalarSize: Option<int> = scalar.lengthtest.assertEq(test.assertSome(arraySize), 2)test.assertEq(test.assertSome(objectSize), 1)test.assertNone(scalarSize)io.writeLine("JSON sizes read")
JSON sizes read
Expected result
Expected result
Execution completes. Exit code 0.
JSON sizes read
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Read JSON object keys
Linkimport std.jsonimport std.testimport std.iolet object = test.assertOk(json.parse("\{\"name\":\"Topaz\"\}"))let array = test.assertOk(json.parse("[]"))let scalar = test.assertOk(json.parse("42"))let names: Option<Array<string>> = object.keystest.assertEq(test.assertSome(names)[0], "name")test.assertNone(array.keys)test.assertNone(scalar.keys)io.writeLine("JSON keys read")
JSON keys read
Expected result
Expected result
Execution completes. Exit code 0.
JSON keys read
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Read JSON object values
Linkimport std.jsonimport std.testimport std.iolet object = test.assertOk(json.parse("\{\"name\":\"Topaz\"\}"))let array = test.assertOk(json.parse("[]"))let scalar = test.assertOk(json.parse("42"))let values = test.assertSome(object.values)test.assertEq(test.assertSome(values[0].asString()), "Topaz")test.assertNone(array.values)test.assertNone(scalar.values)io.writeLine("JSON values read")
JSON values read
Expected result
Expected result
Execution completes. Exit code 0.
JSON values read
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Reject calling Bytes.length
Linkimport std.bytes { Bytes }function inspect(value: Bytes) -> () {let result = value.length()return ()}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5005stdlib-property-not-callable atmain.tpz:3:22
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Reject calling ByteBuffer.length
Linkimport std.bytes { ByteBuffer }function inspect(value: ByteBuffer) -> () {let result = value.length()return ()}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5005stdlib-property-not-callable atmain.tpz:3:22
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Reject calling JSONValue.length
Linkimport std.json { JSONValue }function inspect(value: JSONValue) -> () {let result = value.length()return ()}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5005stdlib-property-not-callable atmain.tpz:3:22
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Reject calling JSONValue.keys
Linkimport std.json { JSONValue }function inspect(value: JSONValue) -> () {let result = value.keys()return ()}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5005stdlib-property-not-callable atmain.tpz:3:22
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Reject calling JSONValue.values
Linkimport std.json { JSONValue }function inspect(value: JSONValue) -> () {let result = value.values()return ()}
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5005stdlib-property-not-callable atmain.tpz:3:22
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 781 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 983 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 734 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 753 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 793 - compiler/crates/topaz_self_frontend/topaz/checker/call_complete.tpz at
271329b482bc· 1328 -
topaz.stdlib.contract.collection-propertiesatworking-tree - topaz.decision.collection-properties.1 at
topaz.decisi
Diagnostics
LinkTest collection emptiness with length
LinkTest collection emptiness with length
Test whether a Bytes, Map, or Set value is empty by comparing its length property with zero. The comparison is true exactly when the collection has no bytes, entries, or elements.
Bytes, Map, and Set do not expose an isEmpty member. Read the length property and use the ordinary equality operator.
Why
A collection already exposes its count through length. Comparing that value with zero expresses emptiness for every collection without another query name or a type-specific method.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Test empty and nonempty maps with length
Linkimport std.iolet empty: Map<string, int> = map {}let filled = map { "one": 1 }io.writeLine("{empty.length == 0}:{filled.length == 0}")
true:false
Expected result
Expected result
Execution completes. Exit code 0.
true:false
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Test empty and nonempty sets with length
Linkimport std.iolet empty: Set<int> = set {}let filled = set { 1 }io.writeLine("{empty.length == 0}:{filled.length == 0}")
true:false
Expected result
Expected result
Execution completes. Exit code 0.
true:false
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Test empty and nonempty byte sequences with length
Linkimport std.bytes { Bytes }import std.testimport std.iolet empty = Bytes.empty()let filled = test.assertOk(Bytes.fromArray([1]))io.writeLine("{empty.length == 0}:{filled.length == 0}")
true:false
Expected result
Expected result
Execution completes. Exit code 0.
true:false
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Reject Bytes.isEmpty
Linkimport std.bytes { Bytes }function inspect(value: Bytes) -> () {let result = value.isEmpty()return ()}
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Reject Map.isEmpty
Linkfunction inspect(value: Map<string, int>) -> () {let result = value.isEmpty()return ()}
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Reject Set.isEmpty
Linkfunction inspect(value: Set<int>) -> () {let result = value.isEmpty()return ()}
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 858 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 863 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 875 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 887 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
271329b482bc· 954 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 487 - compiler/crates/topaz_value/src/value/members.rs at
271329b482bc· 1534 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
271329b482bc· 271 -
topaz.stdlib.contract.collection-emptinessatworking-tree - topaz.decision.length-zero-empty.1 at
topaz.decisi
Diagnostics
LinkConstruct and inspect immutable byte sequences
LinkConstruct and inspect immutable byte sequences
A Bytes value is an immutable ordered sequence of octets. Each octet is an int from 0 through 255.
Bytes.empty returns the empty sequence. Bytes.fromArray accepts an Array<int> and returns an independent snapshot in Ok.
Bytes.fromArray returns Err with a string identifying the first element outside 0 through 255. It does not wrap, clamp, or return a partial sequence.
Bytes.toArray returns a new Array<int> in byte order. Mutating that array or the original input array does not change an existing Bytes value.
Bytes.concat returns the receiver bytes followed by the argument bytes. Either input may be empty and both inputs retain their contents.
Bytes.get uses a zero-based byte index. It returns Some(byte) within the sequence and None() for every negative or past-end index.
Bytes.length is the number of bytes and is read as a property. Compare it with zero to test emptiness.
Receivers and supplied arguments evaluate once from left to right before the operation begins. These operations perform no I/O or text normalization.
A correctly typed lookup or concatenation has no data-dependent Result failure. Allocation exhaustion is an operational failure and is not a decoded data error.
Why
Exact octets keep binary payloads independent of text encoding. Snapshot conversion prevents later array edits from silently changing a payload.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 67 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 73 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 294 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 342 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 351 - compiler/crates/topaz_product_runtime/src/lib.rs at
912a5e86e1f9· 17 -
topaz.stdlib.contract.bytes-valuesatworking-tree
Preserve empty values and byte order
Linkimport std.bytes { Bytes }import std.ioimport std.testlet empty = test.assertOk(Bytes.fromArray([]))let value = test.assertOk(Bytes.fromArray([0, 128, 255]))io.writeLine(Bytes.empty().toHex())io.writeLine(empty.concat(value).toHex())io.writeLine(value.concat(test.assertOk(Bytes.fromArray([1]))).toHex())
0080ff 0080ff01
Expected result
Expected result
Execution completes. Exit code 0.
0080ff0080ff01
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 67 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 73 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 294 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 342 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 351 - compiler/crates/topaz_product_runtime/src/lib.rs at
912a5e86e1f9· 17 -
topaz.stdlib.contract.bytes-valuesatworking-tree
Reject out-of-range array elements
Linkimport std.bytes { Bytes }import std.iofor values in ([[0, -1, 255], [0, 256, 255]]) {match (Bytes.fromArray(values)) {case Err(_) => io.writeLine("invalid byte")case Ok(_) => io.writeLine("accepted")}}
invalid byte invalid byte
Expected result
Expected result
Execution completes. Exit code 0.
invalid byteinvalid byte
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 67 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 73 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 294 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 342 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 351 - compiler/crates/topaz_product_runtime/src/lib.rs at
912a5e86e1f9· 17 -
topaz.stdlib.contract.bytes-valuesatworking-tree
Read optional bytes at both boundaries
Linkimport std.bytes { Bytes }import std.ioimport std.testlet value = test.assertOk(Bytes.fromArray([0, 128, 255]))for index in ([-1, 0, 2, 3]) {match (value.get(index)) {case Some(byte) => io.writeLine("{byte}")case None() => io.writeLine("absent")}}
absent 0 255 absent
Expected result
Expected result
Execution completes. Exit code 0.
absent0255absent
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 67 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 73 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 294 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 342 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 351 - compiler/crates/topaz_product_runtime/src/lib.rs at
912a5e86e1f9· 17 -
topaz.stdlib.contract.bytes-valuesatworking-tree
Keep array edits independent from bytes
Linkimport std.bytes { Bytes }import std.ioimport std.testlet mut input = [0, 255]let value = test.assertOk(Bytes.fromArray(input))let mut output = value.toArray()input[0] = 7output[1] = 8io.writeLine(value.toHex())io.writeLine("{input[0]},{output[1]}")
00ff 7,8
Expected result
Expected result
Execution completes. Exit code 0.
00ff7,8
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 67 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 73 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 294 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 342 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 351 - compiler/crates/topaz_product_runtime/src/lib.rs at
912a5e86e1f9· 17 -
topaz.stdlib.contract.bytes-valuesatworking-tree
Evaluate the receiver before its argument
Linkimport std.bytes { Bytes }import std.iofunction receiver() -> Bytes {io.writeLine("receiver")return "a".encodeUtf8()}function argument() -> Bytes {io.writeLine("argument")return "b".encodeUtf8()}io.writeLine(receiver().concat(argument()).toHex())
receiver argument 6162
Expected result
Expected result
Execution completes. Exit code 0.
receiverargument6162
Source evidence
- compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 67 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 73 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 294 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 342 - compiler/crates/topaz_value/src/value/builtins/bytes.rs at
912a5e86e1f9· 351 - compiler/crates/topaz_product_runtime/src/lib.rs at
912a5e86e1f9· 17 -
topaz.stdlib.contract.bytes-valuesatworking-tree