Closed kateinoigakukun closed 2 years ago
Typealiases in constrained extensions aren't actually constrained today, which means this is allowed as a conformance of P2 when it shouldn't be. (The compiler shouldn't crash, of course.) cc @DougGregor, @slavapestov
You can also get the compiler to crash with the Swift 5 compiler if you add a constraint on the associated type. (Curiously enough, Swift 4.2 doesn't crash here.) (Since it's so similar I just decided to post it here instead of create a new issue.)
protocol AssociatedTypeProto {}
class AssociatedTypeProtoClass: AssociatedTypeProto {}
protocol Proto1 {
associatedtype SameNameAssociatedType: AssociatedTypeProto
}
protocol Proto2 {
associatedtype SameNameAssociatedType: AssociatedTypeProto
}
struct Box<T> {}
extension Box: Proto1 where T: Proto1 {
typealias SameNameAssociatedType = T.SameNameAssociatedType
// typealias SameNameAssociatedType = AssociatedTypeProtoClass // OK
}
extension Box: Proto2 where T: Proto2 {}
This gets you this output on master with assertions enabled:
Invalid conformance substitution
UNREACHABLE executed at /Users/me/Code/swift-source/swift/lib/AST/ProtocolConformance.cpp:130!
Stack dump:
0. Program arguments: /Users/me/Code/swift-source/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-x86_64/bin/swift -frontend -c -primary-file bug.swift -target x86_64-apple-darwin18.2.0 -enable-objc-interop -color-diagnostics -module-name bug -o /var/folders/0j/fm70ht1j0_sg60z_jd0hlmbw0000gp/T/bug-75cb1f.o
1. While emitting witness table for protocol conformance to 'Proto2' (at bug.swift:8:1) for type 'Box<T>' (declared at [bug.swift:12:1 - line:12:16] RangeText="struct Box<T> {")
0 swift 0x000000010bce4d88 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x000000010bce4005 llvm::sys::RunSignalHandlers() + 85
2 swift 0x000000010bce5392 SignalHandler(int) + 258
3 libsystem_platform.dylib 0x00007fff6f0adb3d _sigtramp + 29
4 libsystem_platform.dylib 0x0000000000000046 _sigtramp + 2431984934
5 libsystem_c.dylib 0x00007fff6ef6b1c9 abort + 127
6 swift 0x000000010bc7f5c4 llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 532
7 swift 0x0000000109339689 swift::ProtocolConformanceRef::subst(swift::Type, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<llvm::Optional<swift::ProtocolConformanceRef> (swift::CanType, swift::Type, swift::ProtocolDecl*)>) const + 825
8 swift 0x000000010933933d swift::ProtocolConformanceRef::subst(swift::Type, swift::SubstitutionMap) const + 141
9 swift 0x000000010933f99e swift::SpecializedProtocolConformance::getAssociatedConformance(swift::Type, swift::ProtocolDecl*, swift::LazyResolver*) const + 206
10 swift 0x000000010933f563 swift::ProtocolConformance::getAssociatedConformance(swift::Type, swift::ProtocolDecl*, swift::LazyResolver*) const + 211
11 swift 0x0000000106d011bd (anonymous namespace)::WitnessTableBuilder::addAssociatedConformance(swift::AssociatedConformance) + 301
12 swift 0x0000000106d0094d swift::SILWitnessVisitor<(anonymous namespace)::WitnessTableBuilder>::visitProtocolDecl(swift::ProtocolDecl*) + 829
13 swift 0x0000000106cee91d (anonymous namespace)::WitnessTableBuilder::build() + 61
14 swift 0x0000000106cee49b swift::irgen::IRGenModule::emitSILWitnessTable(swift::SILWitnessTable*) + 299
15 swift 0x0000000106becc75 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1925
16 swift 0x0000000106d8559d performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 2349
17 swift 0x0000000106d8632f swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, llvm::GlobalVariable**) + 655
18 swift 0x0000000106a3006d generateIR(swift::IRGenOptions&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, std::__1::unique_ptr<llvm::Module, std::__1::default_delete<llvm::Module> >&, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >) + 781
19 swift 0x0000000106a0851e performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 6222
20 swift 0x00000001069f9beb performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 2683
21 swift 0x00000001069f7367 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5063
22 swift 0x0000000106913675 run_driver(llvm::StringRef, llvm::ArrayRef<char const*>) + 917
23 swift 0x0000000106911b42 main + 3730
24 libdyld.dylib 0x00007fff6eec2ed9 start + 1
25 libdyld.dylib 0x000000000000000d start + 2433995061
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)
I remember fixing this a while back:
q.swift:15:1: error: type 'Box<T>' does not conform to protocol 'P2'
extension Box: P2 where T: P2 {
^
q.swift:6:20: note: protocol requires nested type 'X'; do you want to add it?
associatedtype X
^
Environment
DEVELOPMENT-SNAPSHOT-2018-12-17-aAdditional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CompilerCrash | |Assignee | @slavapestov | |Priority | Medium | md5: a92d370a0edc9ed1c579e9affae8f3d7Issue Description:
This code doesn't crash. But adding below code results segment fault.