Laythe-lang / Laythe

A gradually typed language originally based on the crafting interpreters series
MIT License
65 stars 4 forks source link

Typed exceptions part 2 #147

Closed jonnyboyC closed 2 months ago

jonnyboyC commented 2 months ago

Problem

In a world where catch block may conditionally work we need to be able to handle that conditional nature. That means we may need to continue to unwind if we don't have an appropriate handler or we may need to jump to a specific handler

Solution

In a sort of pseudo code we'll basically want our execution to flow like this

try {
  something()
} catch: Error1 { 
  // handle somehow 1 
} catch: Error2 { 
  // handle somehow 2
}

// We can think of this as

try {
  something();
} maybeCatch e: Error { // this is any error 
  if e.isA(Error1) { 
    forSureCatch();
    // handle somehow 1
  } else if e.isA(Error2) { 
    forSureCatch();
    // handle somehow 2
  } else { 
    continueUnwind();
  }
}

In the background we'll basically run some instructions to check if the error subclasses the error message handler. then run the handler. If non match then we'll continue the unwind.

This PR in particular implements what is described above as forSureCatch. We still ignore the catch variable and the other catches but have some of the need functionality in place.