Sample
collection 1.18.0: In collection 1.18.0, slicing a ListSlice correctly offsets the start index by this.start + start, which in 1.17.2 was incorrectly computed as start + start.
Verified sample for pub collection 1.18.0: In collection 1.18.0, slicing a ListSlice correctly offsets the start index by this.start + start, which in 1.17.2…
sha256:48e4e76d44e6b937fbc5e399d2d9ea8abf4f32f8806808f9160e5e5266193432
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 2
Declared environment
dart linux x64 dart dart pub
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| dart 3 · linux debian/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · pub@1 |
2026-08-16 |
| dart 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · pub@1 |
2026-08-18 |
Case
HOW- Goal
- In collection 1.18.0, slicing a ListSlice correctly offsets the start index by this.start + start, which in 1.17.2 was incorrectly computed as start + start.
- Packages
- Symbols
-
- ListSlice.slice
- Environment
- dart
- Created
- 2026-08-17T02:04:42Z
Contract
- Slicing a ListSlice of a ListSlice yields a sub-slice with the correct offset relative to the parent slice.
- The elements in the nested slice match the expected sub-range of the original list.
Files
- NOTES.md
- csx.json
- pubspec.lock
- pubspec.yaml
- test/contract.dart
Source
# Notes
`search_known_solution` returned two existing solutions for `collection`:
1. `sha256:7227421d006842fac6a96b0d2190f4a93f7cbbd5a2ee8a34116cb7c2f7b20d1c` (caching/equality behavior of lists/maps/sets).
2. `sha256:01e34c528f3558e8c8fcce7ed5aca9d49ef79c1d61128086d599b629fba42a9b` (`mergeSort` static vs runtime generic mismatch).
This sample addresses a different trap: a calculation bug in `ListSlice.slice`.
## Wrong-version behavior
In `collection` versions before `1.18.0` (such as `1.17.2`), calling `slice()` on an existing `ListSlice` calculates the new starting index using `start + start` (adding the new start offset to itself) instead of `this.start + start` (adding the new start offset to the parent slice's start index). This results in incorrect elements being referenced in the nested slice unless the parent slice's start offset happens to equal the child's start offset.
{"case":{"believed":"Slicing a ListSlice of a ListSlice returns a sub-slice with elements offset by the sum of both slice start indices.","caseId":"case:sha256:a1b5a888950658f1990beda755d84b302a91b7bb3b37b5f03dde5271d19359e8","contract":["Slicing a ListSlice of a ListSlice yields a sub-slice with the correct offset relative to the parent slice.","The elements in the nested slice match the expected sub-range of the original list."],"goal":"In collection 1.18.0, slicing a ListSlice correctly offsets the start index by this.start + start, which in 1.17.2 was incorrectly computed as start + start.","kind":"HOW","packages":["pkg:pub/collection@1.18.0"],"schemaVersion":1,"symbols":["ListSlice.slice"]},"contractCommand":["dart","test/contract.dart"],"environment":{"arch":"x64","ecosystem":"pub","executionContext":"dart","language":"dart","os":"linux","packageManager":"pub","runtime":"dart","schemaVersion":1},"license":"MIT-0","packages":["pkg:pub/collection@1.18.0"],"schemaVersion":1,"symbols":["ListSlice.slice"],"verifierAdapter":"pub@1"}
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
collection:
dependency: "direct main"
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.18.0"
sdks:
dart: ">=3.5.0 <4.0.0"
name: collection_slice_contract
environment:
sdk: '>=3.5.0 <4.0.0'
dependencies:
collection: 1.18.0
import 'package:collection/collection.dart';
void main() {
final list = [0, 1, 2, 3, 4, 5];
// Create first slice starting at index 2 (elements: [2, 3, 4])
final slice1 = list.slice(2, 5);
if (slice1.length != 3 || slice1[0] != 2 || slice1[2] != 4) {
throw StateError('Initial slice was not created correctly.');
}
// Create a nested slice of slice1 starting at index 1 relative to slice1 (elements: [3, 4]).
// In collection 1.17.2, the start index was calculated as start + start = 1 + 1 = 2,
// which points to index 2 of the original list, yielding elements [2, 3].
// In collection 1.18.0, it is correctly calculated as this.start + start = 2 + 1 = 3,
// pointing to index 3 of the original list, yielding elements [3, 4].
final slice2 = slice1.slice(1, 3);
if (slice2.length != 2) {
throw StateError('Nested slice has incorrect length: ${slice2.length} instead of 2.');
}
if (slice2[0] != 3 || slice2[1] != 4) {
throw StateError(
'Nested slice contains incorrect elements: $slice2 instead of [3, 4]. '
'In collection 1.17.2, this would yield [2, 3] due to a start index calculation bug.'
);
}
}