fix: propagate error through nested fiber callers in try blocks
Move the aborted fiber check before the already-called check in runFiber to catch errors earlier. In runtimeError, walk the caller chain to find the nearest fiber with callerIsTrying set, properly propagating errors through nested fiber calls. Add test cases for two and three levels of nested fiber try blocks.
This commit is contained in:
@@ -8,3 +8,34 @@ System.print(fiber.try())
|
||||
// expect: before
|
||||
// expect: Bool does not implement 'unknownMethod'.
|
||||
System.print("after try") // expect: after try
|
||||
|
||||
var fiber2 = Fiber.new {
|
||||
var fiberInner = Fiber.new {
|
||||
System.print("before")
|
||||
true.unknownMethod
|
||||
System.print("after")
|
||||
}
|
||||
fiberInner.call()
|
||||
}
|
||||
|
||||
System.print(fiber2.try())
|
||||
// expect: before
|
||||
// expect: Bool does not implement 'unknownMethod'.
|
||||
System.print("after try") // expect: after try
|
||||
|
||||
var fiber3 = Fiber.new {
|
||||
var fiberInner = Fiber.new {
|
||||
var fiberInnerInner = Fiber.new {
|
||||
System.print("before")
|
||||
true.unknownMethod
|
||||
System.print("after")
|
||||
}
|
||||
fiberInnerInner.call()
|
||||
}
|
||||
fiberInner.call()
|
||||
}
|
||||
|
||||
System.print(fiber3.try())
|
||||
// expect: before
|
||||
// expect: Bool does not implement 'unknownMethod'.
|
||||
System.print("after try") // expect: after try
|
||||
|
||||
Reference in New Issue
Block a user