File tree Expand file tree Collapse file tree 3 files changed +14
-18
lines changed Expand file tree Collapse file tree 3 files changed +14
-18
lines changed Original file line number Diff line number Diff line change @@ -1127,10 +1127,12 @@ namespace {
1127
1127
protected:
1128
1128
int64_t getDiscriminatorIndex (EnumElementDecl *target) const override {
1129
1129
// The elements are assigned discriminators ABI-compatible with their
1130
- // raw values from C.
1131
- assert (target->getRawValueExpr ()
1132
- && " c-compatible enum elt has no raw value?!" );
1133
- auto intExpr = cast<IntegerLiteralExpr>(target->getRawValueExpr ());
1130
+ // raw values from C. An invalid raw value is assigned the error index -1.
1131
+ auto intExpr =
1132
+ dyn_cast_or_null<IntegerLiteralExpr>(target->getRawValueExpr ());
1133
+ if (!intExpr) {
1134
+ return -1 ;
1135
+ }
1134
1136
auto intType = getDiscriminatorType ();
1135
1137
1136
1138
APInt intValue =
Original file line number Diff line number Diff line change @@ -4187,20 +4187,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
4187
4187
auto nominal = cast<NominalTypeDecl>(D);
4188
4188
Type declaredInterfaceTy = nominal->getDeclaredInterfaceType ();
4189
4189
nominal->setInterfaceType (MetatypeType::get (declaredInterfaceTy, Context));
4190
-
4191
- if (auto *ED = dyn_cast<EnumDecl>(nominal)) {
4192
- // @objc enums use their raw values as the value representation, so we
4193
- // need to force the values to be checked even in non-primaries.
4194
- //
4195
- // FIXME: This check can be removed once IRGen can be made tolerant of
4196
- // semantic failures post-Sema.
4197
- if (ED->isObjC ()) {
4198
- (void )evaluateOrDefault (
4199
- Context.evaluator ,
4200
- EnumRawValuesRequest{ED, TypeResolutionStage::Interface}, true );
4201
- }
4202
- }
4203
-
4204
4190
break ;
4205
4191
}
4206
4192
Original file line number Diff line number Diff line change 1
1
// RUN: not %target-swift-frontend -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D NO_RAW_TYPE 2>&1 | %FileCheck -check-prefix=NO_RAW_TYPE %s
2
2
// RUN: not %target-swift-frontend -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D BAD_RAW_TYPE 2>&1 | %FileCheck -check-prefix=BAD_RAW_TYPE %s
3
3
// RUN: not %target-swift-frontend -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D NON_INT_RAW_TYPE 2>&1 | %FileCheck -check-prefix=NON_INT_RAW_TYPE %s
4
+ // RUN: not %target-swift-frontend -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D NON_INT_RAW_VALUE 2>&1 | %FileCheck -check-prefix=NON_INT_RAW_VALUE %s
4
5
// RUN: not %target-swift-frontend -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D NO_CASES 2>&1 | %FileCheck -check-prefix=NO_CASES %s
5
6
// RUN: not %target-swift-frontend -module-name main %s -primary-file %S/Inputs/objc_enum_multi_file_helper.swift -emit-ir -D DUPLICATE_CASES 2>&1 | %FileCheck -check-prefix=DUPLICATE_CASES %s
6
7
// Note that the *other* file is the primary file in this test!
38
39
// DUPLICATE_CASES: :[[@LINE-4]]:8: note: raw value implicitly auto-incremented from zero
39
40
}
40
41
42
+ #elseif NON_INT_RAW_VALUE
43
+ @objc enum TheEnum : Int32 {
44
+ case A = 0
45
+ case B = " B "
46
+ // NON_INT_RAW_VALUE: :[[@LINE-1]]:12: error: cannot convert value of type 'String' to raw type 'Int32'
47
+ }
48
+
41
49
#else
42
50
enum TheEnum : Invalid { // should never be hit
43
51
case A
You can’t perform that action at this time.
0 commit comments