Skip to content

[SR-6897] Compiler crashes when giving enum a raw value type of ExpressibleByStringLiteral struct #49446

@itaiferber

Description

@itaiferber
Previous ID SR-6897
Radar rdar://problem/37133177
Original Reporter @itaiferber
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: e4ee1ad5598af9e29fb79ab35d7c4887

Issue Description:

The following code compiles:

struct S : ExpressibleByStringLiteral {
    init(stringLiteral: String) {}
}

The following does not:

struct S : ExpressibleByStringLiteral {
    init(stringLiteral: String) {}
}

enum E : S {}

producing

Untitled.swift:7:10: error: an enum with no cases cannot declare a raw type
enum E : S {}
         ^
Untitled.swift:7:10: error: 'E' declares raw type 'S', but does not conform to RawRepresentable and conformance could not be synthesized
enum E : S {}
         ^
Untitled.swift:7:10: error: RawRepresentable conformance cannot be synthesized because raw type 'S' is not Equatable
enum E : S {}
         ^
Swift.RawRepresentable:94:20: note: protocol requires nested type 'RawValue'; do you want to add it?
    associatedtype RawValue
                   ^

Adding RawValue as recommended cuts down on the errors:

struct S : ExpressibleByStringLiteral {
    init(stringLiteral: String) {}
}

enum E : S {
    typealias RawValue = S
}

produces

Untitled.swift:7:10: error: an enum with no cases cannot declare a raw type
enum E : S {
         ^

Adding a case crashes the compiler:

import Foundation

struct S : ExpressibleByStringLiteral {
    init(stringLiteral: String) {}
}

enum E : S {
    typealias RawValue = S
    case a = "a"
}

produces

0  swift                    0x00000001084517da PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000108450c96 SignalHandler(int) + 598
2  libsystem_platform.dylib 0x00007fff63ec2dfa _sigtramp + 26
3  libsystem_platform.dylib 0x00007f817a2b38b0 _sigtramp + 373230288
4  swift                    0x0000000105577a69 swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::visitProtocolDecl(swift::ProtocolDecl*) + 761
5  swift                    0x0000000105576788 swift::Lowering::SILGenModule::getWitnessTable(swift::ProtocolConformance*) + 488
6  swift                    0x000000010557b194 (anonymous namespace)::SILGenType::emitType() + 2308
7  swift                    0x000000010549b67a swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 74
8  swift                    0x000000010549a93b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 1115
9  swift                    0x000000010549c2c9 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool) + 841
10 swift                    0x0000000104bfae14 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 12980
11 swift                    0x0000000104bf62d9 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 8697
12 swift                    0x0000000104ba739e main + 13918
13 libdyld.dylib            0x00007fff63cd1f29 start + 1
14 libdyld.dylib            0x000000000000000e start + 2620580070
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file Untitled.swift -target x86_64-apple-darwin18.0.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -module-name Untitled -o /var/folders/0_/2gdgjnt94rj7hqjcrnkh4m3c0000gn/T/Untitled-ea6dbb.o 
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions