add float constraint type
This commit is contained in:
@@ -181,7 +181,29 @@
|
||||
- disallow: `b :: undefined` since assigning undefined to something that can't change defeats the purpose
|
||||
- disallow assigning `undefined` after declaration; use optionals and `none` for values that intentionally move back to an empty state
|
||||
|
||||
13. broaden type inference from surrounding context
|
||||
13. introduce a `float` type constraint (similar to `int`) (implemented)
|
||||
- resolves a local binding to any float scalar (`f32`/`f64`) via static analysis; widens
|
||||
`f32` -> `f64` across assignments, mirroring how `int` picks the smallest fitting integer
|
||||
- on a local declaration, integer literals satisfy `float` and default to `f64`
|
||||
(`pi float = 3` is `3.0`); a runtime integer (`x float = some_i32`) stays a
|
||||
`cannot implicitly convert` error
|
||||
- a local initializer whose numeric family doesn't satisfy the constraint now errors for
|
||||
both `int` and `float` instead of silently taking the initializer's natural type
|
||||
- as with `int`, a constraint in a param/result position is a generic passthrough (it
|
||||
forwards the inferred type unchanged, e.g. an identity `func(v int) int` over a range),
|
||||
so the literal-as-float and family checks apply to local bindings, not passthroughs
|
||||
|
||||
14. add slice-by-range
|
||||
- allow the use of a range in slice expressions:
|
||||
```
|
||||
excl_range range :: 0..10
|
||||
some_arr[excl_range] # slice by named exclusive range
|
||||
|
||||
incl_range range :: 0..=10
|
||||
some_arr[incl_range] # slice by named inclusive range
|
||||
```
|
||||
|
||||
15. broaden type inference from surrounding context
|
||||
|
||||
## A word on multi-unwrap
|
||||
|
||||
|
||||
Reference in New Issue
Block a user