Details
-
Type:
Improvement
-
Status: Open
-
Priority:
Medium
-
Resolution: Unresolved
-
Component/s: Compiler
-
Labels:
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).
Attachments
Issue Links
- relates to
-
SR-12998 Raw Value of literal String #file breaks enum with String Protocol
-
- Resolved
-