disambiguate enum blocks and complete distinct type operations

This commit is contained in:
2026-08-01 23:57:35 +02:00
parent 91aa601464
commit b9526b5f06
34 changed files with 1128 additions and 1963359 deletions
+23 -12
View File
@@ -139,10 +139,12 @@
8. distinct types (implemented; see below)
- nominal declarations preserve identity across packages and reuse the backing runtime representation
- construction uses `Type(value)` with exactly one value of the exact backing type
- no implicit conversion to or from the backing type
- backing-type operators and reverse explicit conversions remain deferred
- concrete runtime backing types are supported; unresolved, `int`, `void`, function, and opaque backings are rejected
- construction accepts exactly one value of the immediate backing type; no implicit conversion
crosses the nominal boundary or mixes separate distinct declarations
- explicit scalar casts extract one declared distinct layer at a time
- scalar-backed values support matching runtime/comptime arithmetic, bitwise, shift, comparison,
compound-assignment, bounds, indexing, reflection, and standard formatting behavior
- unresolved, `int`, `void`, function, and opaque backings remain invalid runtime declarations
9. allow pointer field access pass-through (implemented)
- having a pointer (`ptr`) to a struct, we should allow access through `ptr.field` as opposed to mandating `ptr^.field`
@@ -829,9 +831,6 @@
conflicting targets
- root `std` re-exports only `ArrayList(T)` for now; operations remain under `std/arraylist`
35. syntax highlighting (tree-sitter) updates (implemented)
- pointer sigils are highlighted as operators
- type-factory calls in type positions and struct literals are highlighted as functions
36. transitive package namespaces (spike completed; no language change)
- imports remain file-local implementation details, including explicitly named imports such as
@@ -1062,16 +1061,28 @@ For-loop captures are immutable and scoped to the loop body. Sequence index capt
## A word on distinct types
Distinct types are considered distinct from their backing type. They do not implicitly coerce to their backing type.
Distinct declarations are nominal even when they share a backing type. Construction requires the
exact immediate backing, implicit conversion is forbidden in either direction, and an explicit
scalar cast extracts one layer:
```
# distinct type
```bro
UserID :: distinct u32
OuterID :: distinct UserID
# instantiate distinct type
my_id UserID :: UserID(42) # value must have the exact backing type
id UserID :: UserID(u32(42))
raw u32 :: u32(id)
outer OuterID :: OuterID(id)
inner UserID :: UserID(outer)
```
Scalar-backed distinct values retain their nominal type across the operations supported by the
backing scalar. Integer forms support checked arithmetic, bitwise operations, shifts, comparisons,
compound assignments, indexing, slicing, and `minval!` / `maxval!`; float forms support arithmetic
and comparisons; boolean forms support equality and inequality. Separate distinct identities and
typed backing operands never mix, though literals receive the distinct context. Runtime and
comptime rules are identical. Reflection reports the immediate backing, while standard formatting
recursively follows nested distinct backings to the final scalar.
## A word on enums
```