You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thoughts on further improvements after #7688 is merged.
Right now, TryAnalyzer assumes that a Throwable could be thrown at any point in the try block, and no uncaught Throwable will ever be thrown in a catch block. A better option would be to keep track of possibly throwing statements and track the possibilities for each variable before each possibly throwing statement.
TryCatchScope would have to be changed so that instead of tracking all assignments in the scope, it should clone all variable states before each possibly throwing statement, then TryAnalyzer could use that data to union the possible types instead of using the assignment data.
The main difficulty here is figuring out which statements can throw. We can use @throws, but that's potentially dangerous if one is missing. checkForThrowsDocblock helps for user code but not for dependencies, so maybe we'd just want to assume all non-internal functions can throw Throwable? Maybe we should add a config option to toggle that behavior for user code and/or library code? We would also have to track down every type of statement that can cause an Error, like 1 / 0.
#2912 could make this much less dangerous. If we assume any function without a @throws annotation can throw Throwable, this might actually work fairly well. I think for it to be completely safe we'd also have to show a warning when calling a function without any @throws or @psalm-never-throw inside a function with @throws SomeException, since it might throw a Throwable.
The text was updated successfully, but these errors were encountered:
The behaviour right now is dumb, but it can be understood by user easily. Trying to make it a super smart behaviour that users won't understand may not be a good move either...
Thoughts on further improvements after #7688 is merged.
Right now, TryAnalyzer assumes that a
Throwable
could be thrown at any point in thetry
block, and no uncaughtThrowable
will ever be thrown in a catch block. A better option would be to keep track of possibly throwing statements and track the possibilities for each variable before each possibly throwing statement.TryCatchScope would have to be changed so that instead of tracking all assignments in the scope, it should clone all variable states before each possibly throwing statement, then TryAnalyzer could use that data to union the possible types instead of using the assignment data.
The main difficulty here is figuring out which statements can throw. We can use
@throws
, but that's potentially dangerous if one is missing.checkForThrowsDocblock
helps for user code but not for dependencies, so maybe we'd just want to assume all non-internal functions can throwThrowable
? Maybe we should add a config option to toggle that behavior for user code and/or library code? We would also have to track down every type of statement that can cause anError
, like1 / 0
.#2912 could make this much less dangerous. If we assume any function without a
@throws
annotation can throwThrowable
, this might actually work fairly well. I think for it to be completely safe we'd also have to show a warning when calling a function without any@throws
or@psalm-never-throw
inside a function with@throws SomeException
, since it might throw aThrowable
.The text was updated successfully, but these errors were encountered: