[fine] While loops, nothing
This commit is contained in:
parent
1cc5ce6ca9
commit
ac3c158a81
7 changed files with 166 additions and 48 deletions
|
|
@ -46,7 +46,7 @@ fun attack(weapon: MeleeWeapon or RangedWeapon, monster: Monster, distance: f64)
|
|||
// from the `is` binding in scope.
|
||||
if weapon is MeleeWeapon and distance > 1 or
|
||||
weapon is w : RangedWeapon and (distance < w.minRange or distance > w.maxRange) {
|
||||
print("You are out of range")
|
||||
print("You are out of range");
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ fun attack(weapon: MeleeWeapon or RangedWeapon, monster: Monster, distance: f64)
|
|||
}
|
||||
}
|
||||
|
||||
fun more_examples(weapon: MeleeWeapon or RangedWeapon) -> f64 or () {
|
||||
fun more_examples(weapon: MeleeWeapon or RangedWeapon) -> f64 or nothing {
|
||||
if weapon is w: RangedWeapon and w.maxRange > 10 {
|
||||
// w is still in scope here; the `and` is bound into a predicate expression
|
||||
// and breaks exhaustivity
|
||||
|
|
@ -115,7 +115,7 @@ fun test() -> f64 {
|
|||
|
||||
// Unroll by hand...
|
||||
let it = new Iterator { current: 0 };
|
||||
loop {
|
||||
while true {
|
||||
if it.next() is v: f64 {
|
||||
sum = sum + v;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ fun test() {
|
|||
// | 1: Return
|
||||
// |
|
||||
// @eval: Nothing
|
||||
// @type: 15 ()
|
||||
// @type: 15 nothing
|
||||
// @concrete:
|
||||
// | File
|
||||
// | FunctionDecl
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
if (if false { true }) { 32 } else { 23 }
|
||||
|
||||
// @expect-errors:
|
||||
// | 1:4: the type of the 'then' branch ('bool') must match the type of the 'else' branch ('()')
|
||||
// | 1:4: the type of the 'then' branch ('bool') must match the type of the 'else' branch ('nothing')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue