ChildsplayOSU / bogl

Haskell implementation of the BoGL language
https://bogl.engr.oregonstate.edu
BSD 3-Clause "New" or "Revised" License
7 stars 1 forks source link

unpackBool Hides Runtime Stack Overflows #158

Closed montymxb closed 3 years ago

montymxb commented 3 years ago

The following program shows that a function which can overflow the runtime stack, and should return a bool, ends up covering up the runtime error with an adhoc error (one which I was responsible for putting in much earlier this year).

-- fails to evaluate due to our internal stack limit
infin : Int -> Bool
infin(x) = if x > 0 then infin(x+1) else True

-- attempts to unpack the boolean for use from 'infin(x)', discards the runtime error,
-- and replaces it with a generic 'expr did not eval to bool' runtime errror
boolHides : Int -> Bool
boolHides(x) = if infin(x) then True else False
> boolHides(1)

Runtime Error: "The expression infin(x) did not evaluate to a Bool as expected!"

This only occurs when the value needs to be inspected, writing just infin(x) returns an error appropriately.

A possible solution would be to refactor the unpackBool logic, such that it properly forwards Err as well as Vb values to be handled by the caller. There are only two locations where it is used, while and if-then-else.

montymxb commented 3 years ago

As an additional note, this runtime checking of expressions used in conditionals should be phased out with the new typechecker, so that is also something that will be removed separately down the road.