Finch/tests/new/defaults_numbers.fch
Nexoniarz 6142e47e71 Struct defaults apply inside structs; exit() ends an or-block; 1e9 literals; x * 2.0 stays f32; floats print as the shortest exact text; str(x, digits)
Also frees main's args and the message of a failing main (valgrind was not clean on two tests).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 09:14:58 +01:00

43 lines
956 B
Text

// struct defaults apply inside structs too; number literals and float text
struct Audio {
int rate = 48000
float volume = 0.8
}
struct Mixer {
Audio audio
[]Audio extra
int voices = 5
}
struct Box[T] {
T item
Audio audio
}
fn make() -> Mixer {
Mixer m
return m
}
fn scale(f32 x) -> f32 {
return x * 2.0 + 1
}
fn main() {
a := Mixer()
Mixer b
c := Mixer(voices: 2)
list := [Mixer()]
m := ["x": Mixer()]
map[str]Mixer counts
counts["new"].voices += 1
bx := Box[int]()
print(a.audio.rate, b.audio.volume, c.audio.rate, c.voices, list[0].audio.rate, m["x"].audio.rate)
print(make().audio.rate, counts["new"].audio.rate, counts["new"].voices, bx.audio.rate)
print(1e3, 2.5e-3, 1E+6, 1_000.5e1, scale(1.5))
print(1.0 / 3.0, 0.1 + 0.2, 100000000.0, 1e20, 1e-7, float(7), f32(0.1))
print(str(3.14159, 2), str(2, 1), str(f32(0.1)), "x=" + str(0.25), [0.5, 1.25])
}