File tree Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Original file line number Diff line number Diff line change 13
13
// This file defines all of the kinds of macro roles. Clients should define
14
14
// either MACRO_ROLE or both ATTACHED_MACRO_ROLE and FREESTANDING_MACRO_ROLE.
15
15
//
16
+ // The order of the macro roles in this file is significant for the
17
+ // serialization of module files. Please do not re-order the entries without
18
+ // also bumping the module format version. When introducing new macro roles,
19
+ // please add them to the end of the file.
20
+ //
16
21
// ===----------------------------------------------------------------------===//
17
22
18
23
#ifndef ATTACHED_MACRO_ROLE
Original file line number Diff line number Diff line change 28
28
#include " swift/AST/Initializer.h"
29
29
#include " swift/AST/MacroDiscriminatorContext.h"
30
30
#include " swift/AST/Module.h"
31
+ #include " swift/AST/NameLookup.h"
31
32
#include " swift/AST/ParameterList.h"
32
33
#include " swift/AST/Pattern.h"
33
34
#include " swift/AST/PrettyStackTrace.h"
@@ -1021,13 +1022,22 @@ class Verifier : public ASTWalker {
1021
1022
1022
1023
void verifyChecked (ThrowStmt *S) {
1023
1024
Type thrownError;
1024
- if (!Functions.empty ()) {
1025
- if (auto fn = AnyFunctionRef::fromDeclContext (Functions.back ()))
1026
- thrownError = fn->getThrownErrorType ();
1025
+ SourceLoc loc = S->getThrowLoc ();
1026
+ if (loc.isValid ()) {
1027
+ auto catchNode = ASTScope::lookupCatchNode (getModuleContext (), loc);
1028
+ if (catchNode) {
1029
+ if (auto thrown = catchNode.getThrownErrorTypeInContext (Ctx)) {
1030
+ thrownError = *thrown;
1031
+ } else {
1032
+ thrownError = Ctx.getNeverType ();
1033
+ }
1034
+ } else {
1035
+ thrownError = checkExceptionTypeExists (" throw expression" );
1036
+ }
1037
+ } else {
1038
+ return ;
1027
1039
}
1028
1040
1029
- if (!thrownError)
1030
- thrownError = checkExceptionTypeExists (" throw expression" );
1031
1041
checkSameType (S->getSubExpr ()->getType (), thrownError, " throw operand" );
1032
1042
verifyCheckedBase (S);
1033
1043
}
Original file line number Diff line number Diff line change @@ -130,6 +130,23 @@ open class MyClass {
130
130
func f( ) throws { }
131
131
}
132
132
133
+
134
+ struct Foo : Error { }
135
+ struct Bar : Error { }
136
+
137
+ // CHECK-LABEL: sil hidden [ossa] @$s12typed_throws0B22DifferentFromEnclosingyyAA3FooVYKF : $@convention(thin) () -> @error Foo
138
+ func throwsDifferentFromEnclosing( ) throws ( Foo) {
139
+ do {
140
+ throw Bar ( )
141
+ } catch {
142
+ print ( " Bar was barred " )
143
+ }
144
+
145
+ // CHECK: throw [[ERROR:%.*]] : $Foo
146
+ throw Foo ( )
147
+ }
148
+
149
+
133
150
// CHECK-LABEL: sil_vtable MySubclass {
134
151
// CHECK-NEXT: #MyClass.init!allocator: <E where E : Error> (MyClass.Type) -> (() throws(E) -> ()) throws(E) -> MyClass : @$s12typed_throws10MySubclassC4bodyACyyxYKXE_txYKcs5ErrorRzlufC [override]
135
152
// CHECK-NEXT: #MyClass.f: (MyClass) -> () throws -> () : @$s12typed_throws10MySubclassC1fyyAA0C5ErrorOYKFAA0C5ClassCADyyKFTV [override]
You can’t perform that action at this time.
0 commit comments