We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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:
RawValue
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" }
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)
The text was updated successfully, but these errors were encountered:
@swift-ci Create
Sorry, something went wrong.
From https://twitter.com/tmpz/status/959178016122458112
Interestingly, looks like this is fixed by adding Equatable conformance:
Equatable
struct S : ExpressibleByStringLiteral, Equatable { let value: String init(stringLiteral: String) { value = stringLiteral } static func ==(_ lhs: S, _ rhs: S) -> Bool { return lhs.value == rhs.value } } enum E : S { typealias RawValue = S case a = "a" } print(E.a) // => a
Comment by Tommaso Piazza (JIRA)
@itaiferber Equatable is also what makes https://bugs.swift.org/browse/SR-6899 compile in the first place with `Foo` backed by RawValue String
I was investigating this - another fix is to add a rawValue computed property and rawValue initialiser.
rawValue
Here's a fix: #27050
#29173
No branches or pull requests
Additional Detail from JIRA
md5: e4ee1ad5598af9e29fb79ab35d7c4887
Issue Description:
The following code compiles:
The following does not:
producing
Adding
RawValue
as recommended cuts down on the errors:produces
Adding a case crashes the compiler:
produces
The text was updated successfully, but these errors were encountered: