show error on duplicated level number

pull/116/head
Jon 3 years ago
parent c50517b5e6
commit 6e046d72b6

@ -382,8 +382,13 @@ def modifyCurWorld (fn : World → m World) [MonadError m] : m Unit := do
return {game with worlds := {game.worlds with nodes := game.worlds.nodes.insert world.name (← fn world) }} return {game with worlds := {game.worlds with nodes := game.worlds.nodes.insert world.name (← fn world) }}
def addLevel (level : GameLevel) [MonadError m] : m Unit := do def addLevel (level : GameLevel) [MonadError m] : m Unit := do
modifyCurWorld fun world => do let worldId ← getCurWorldId
return {world with levels := world.levels.insert level.index level} match ← getLevel? ⟨← getCurGameId, worldId, level.index⟩ with
| some _existingLevel =>
throwError m!"Level {level.index} already exists for world {worldId}!"
| none =>
modifyCurWorld fun world => do
return {world with levels := world.levels.insert level.index level}
def getCurLevel [MonadError m] : m GameLevel := do def getCurLevel [MonadError m] : m GameLevel := do
let some level := (← getCurWorld).levels.find? (← getCurLevelIdx) let some level := (← getCurWorld).levels.find? (← getCurLevelIdx)

@ -13,8 +13,11 @@ Level 1
Statement foo.bar : 5 ≤ 7 := by Statement foo.bar : 5 ≤ 7 := by
simp simp
-- Shows warning on `foo.bar₂`: Game "Test"
World "TestW"
Level 2 -- should warn if set to `1`
-- Shows warning on `foo.bar₂`:
Statement foo.bar2 : 3 ≤ 7 := by Statement foo.bar2 : 3 ≤ 7 := by
simp simp

Loading…
Cancel
Save