Skip to content

Commit b6047e2

Browse files
authored
Merge pull request swiftlang#41796 from nkcsgexi/90168664
sema: reject enum element call with payloads as compile-time constant
2 parents d397821 + 000a41d commit b6047e2

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/Sema/CSFix.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,9 @@ bool NotCompileTimeConst::diagnose(const Solution &solution, bool asNote) const
11461146
// Referencing an enum element directly is considered a compile-time literal.
11471147
if (auto *d = solution.resolveLocatorToDecl(locator).getDecl()) {
11481148
if (isa<EnumElementDecl>(d)) {
1149-
return true;
1149+
if (!d->hasParameterList()) {
1150+
return true;
1151+
}
11501152
}
11511153
}
11521154
NotCompileTimeConstFailure failure(solution, locator);

test/Sema/const_enum_elements.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %target-typecheck-verify-swift
22

33
enum CarKind {
4+
static let wagon = "Wagon"
45
case coupe
56
case sedan
67
case other(String)
@@ -21,7 +22,8 @@ func main() {
2122
drive(.sedan, k2: .coupe)
2223
drive(CarKind.coupe, k2: CarKind.sedan)
2324
drive(CarKind.sedan, k2: CarKind.coupe)
24-
drive(.other(""), k2: .sedan)
25+
drive(.other(""), k2: .sedan) // expected-error {{expect a compile-time constant literal}}
26+
drive(.other(CarKind.wagon), k2: .sedan) // expected-error {{expect a compile-time constant literal}}
2527

2628
drive(.myCoupe, k2: .sedan) // expected-error {{expect a compile-time constant literal}}
2729
drive(.coupe, k2: .myCoupe) // expected-error {{expect a compile-time constant literal}}

0 commit comments

Comments
 (0)