@@ -1918,6 +1918,7 @@ class TryExpr : public AnyTryExpr {
19181918// / should dynamically assert if it does.
19191919class ForceTryExpr final : public AnyTryExpr {
19201920 SourceLoc ExclaimLoc;
1921+ Type thrownError;
19211922
19221923public:
19231924 ForceTryExpr (SourceLoc tryLoc, Expr *sub, SourceLoc exclaimLoc,
@@ -1927,6 +1928,15 @@ class ForceTryExpr final : public AnyTryExpr {
19271928
19281929 SourceLoc getExclaimLoc () const { return ExclaimLoc; }
19291930
1931+ // / Retrieve the type of the error thrown from the subexpression.
1932+ Type getThrownError () const { return thrownError; }
1933+
1934+ // / Set the type of the error thrown from the subexpression.
1935+ void setThrownError (Type type) {
1936+ assert (!thrownError || thrownError->isEqual (type));
1937+ thrownError = type;
1938+ }
1939+
19301940 static bool classof (const Expr *e) {
19311941 return e->getKind () == ExprKind::ForceTry;
19321942 }
@@ -1937,6 +1947,7 @@ class ForceTryExpr final : public AnyTryExpr {
19371947// / Optional. If the code does throw, \c nil is produced.
19381948class OptionalTryExpr final : public AnyTryExpr {
19391949 SourceLoc QuestionLoc;
1950+ Type thrownError;
19401951
19411952public:
19421953 OptionalTryExpr (SourceLoc tryLoc, Expr *sub, SourceLoc questionLoc,
@@ -1946,6 +1957,15 @@ class OptionalTryExpr final : public AnyTryExpr {
19461957
19471958 SourceLoc getQuestionLoc () const { return QuestionLoc; }
19481959
1960+ // / Retrieve the type of the error thrown from the subexpression.
1961+ Type getThrownError () const { return thrownError; }
1962+
1963+ // / Set the type of the error thrown from the subexpression.
1964+ void setThrownError (Type type) {
1965+ assert (!thrownError || thrownError->isEqual (type));
1966+ thrownError = type;
1967+ }
1968+
19491969 static bool classof (const Expr *e) {
19501970 return e->getKind () == ExprKind::OptionalTry;
19511971 }
0 commit comments