-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
compilerThe Swift compiler itselfThe Swift compiler itselfimprovementtype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis
Description
Previous ID | SR-13022 |
Radar | None |
Original Reporter | @theblixguy |
Type | Improvement |
Additional Detail from JIRA
Votes | 1 |
Component/s | Compiler |
Labels | Improvement, TypeChecker |
Assignee | None |
Priority | Medium |
md5: 89b49aa4c8519ddc9542ad6e2571af4e
relates to:
- SR-12998 Raw Value of literal String #file breaks enum with String Protocol
Issue Description:
Currently, the use of a magic literal (such as #file
) as a raw value for an enum case:
enum Foo: String {
case bar = #file
}
triggers an error: use of '#file' literal as raw value for enum case is not supported
.
We should support use of a limited set of magic literals as raw values. The eligible literals would be #file
, #filePath
, #function
, #line
and #column
since their raw value types can be used as the raw type for an enum:
enum FooString: String {
case bar = #file // okay, #file is String which matches the raw type
}
enum FooInt: Int {
case bar = #line // okay, #line is Int which matches the raw type
}
#line
and #column
can be easily fetched from the SourceManager
, and the same with #file
and #filePath
I believe. #function
name can be fetched by moving getMagicFunctionName
from SILGen into AST (as a method on DeclContext).
Metadata
Metadata
Assignees
Labels
compilerThe Swift compiler itselfThe Swift compiler itselfimprovementtype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis