Skip to content

Commit 8bca045

Browse files
committed
[AST] Fail to compute the EnumElementDecl type in case of an ErrorType
If the resulting function type contains an ErrorType, this is an indicator that something else is wrong. Bail out in this case. This happened if an enum case was referenced inside the where-clause and treated as a type.
1 parent a341b0f commit 8bca045

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4311,8 +4311,13 @@ SourceRange EnumElementDecl::getSourceRange() const {
43114311

43124312
bool EnumElementDecl::computeType() {
43134313
EnumDecl *ED = getParentEnum();
4314-
43154314
Type resultTy = ED->getDeclaredTypeInContext();
4315+
4316+
if (resultTy->is<ErrorType>()) {
4317+
setType(resultTy);
4318+
return false;
4319+
}
4320+
43164321
Type argTy = MetatypeType::get(resultTy);
43174322

43184323
// The type of the enum element is either (T) -> T or (T) -> ArgType -> T.

test/Generics/generic_types.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,5 @@ struct UnsolvableInheritance1<T : T.A> {}
334334
struct UnsolvableInheritance2<T : U.A, U : T.A> {}
335335
// expected-error@-1 {{inheritance from non-protocol, non-class type 'U.A'}}
336336
// expected-error@-2 {{inheritance from non-protocol, non-class type 'T.A'}}
337+
338+
enum X7<T where X7.X : G> { case X } // expected-error{{'X' is not a member type of 'X7<T>'}}

validation-test/compiler_crashers/28224-swift-genericfunctiontype-get.swift renamed to validation-test/compiler_crashers_fixed/28224-swift-genericfunctiontype-get.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// See http://swift.org/LICENSE.txt for license information
66
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -parse
8+
// RUN: not %target-swift-frontend %s -parse
99
// REQUIRES: asserts
1010
{enum S<T where S.c:A{case c

0 commit comments

Comments
 (0)