[fine] Report errors with environments, fix match bug

I'm worried that this will turn into something I always have to do
instead of something I just do sometimes: always provide the
provenance of some error type or another. Link error types to
diagnostics, etc.
This commit is contained in:
John Doty 2024-03-24 08:15:33 -07:00
parent 2ba34701ac
commit 8779aade24
3 changed files with 41 additions and 30 deletions

View file

@ -46,13 +46,17 @@ class Monster {
fun print(x:string) {}
fun in_range(weapon: MeleeWeapon or RangedWeapon, distance: f64) {
fun in_range(weapon: MeleeWeapon or RangedWeapon, distance: f64) -> bool {
match weapon {
w:RangedWeapon -> distance >= w.minRange and distance <= w.maxRange,
_ -> distance == 1
}
}
fun roll_dice(x:f64) -> f64 {
0
}
fun attack(weapon: MeleeWeapon or RangedWeapon, monster: Monster, distance: f64) {
// This is worse than Bob's final version but but it works. `is` operator
// should be the same precedence as `and` and left-associative, so the
@ -79,10 +83,10 @@ fun attack(weapon: MeleeWeapon or RangedWeapon, monster: Monster, distance: f64)
if monster.health <= damage {
print("You kill the monster!");
monster.health = 0
monster.health = 0;
} else {
print("You wound the monster.");
monster.health = monster.health - damage
monster.health = monster.health - damage;
}
}
@ -147,6 +151,5 @@ fun test() -> f64 {
// like the above.
}
// @ignore not finished yet, still compiler bugs
// @no-errors
// @eval: Float(90.0)
// @eval: Float(190.0)