You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-55 non-@objc protocol existentials do not conform to their own protocol type
Issue Description:
Summary
Within Xcode (or Playground), when creating a new class which conforms to a generic protocol with associatedtype with a type constraint, defining the typealias with a protocol composition causes the compiler to crash.
I couldn't reproduce this in REPL (see attached screenshot).
How to reproduce?
Tested with Xcode 9.2, i. e. toolchain for Swift 4.0.3 Release
Assertion failed: (expectedSchema.size() == IGF.IGM.getExplosionSize(applyContextArchetypes(IGF, substTy))), function reemitAsUnsubstituted, file /Users/buildnode/jenkins/workspace/oss-swift-4.0-package-osx/swift/lib/IRGen/GenPoly.cpp, line 66.
0 swift 0x000000010f527f38 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x000000010f526e96 llvm::sys::RunSignalHandlers() + 86
2 swift 0x000000010f5284fe SignalHandler(int) + 366
3 libsystem_platform.dylib 0x00007fff65999f5a _sigtramp + 26
4 libsystem_platform.dylib 000000000000000000 _sigtramp + 2590400704
5 libsystem_c.dylib 0x00007fff657371ae abort + 127
6 libsystem_c.dylib 0x00007fff656ff1ac basename_r + 0
7 swift 0x000000010c5b7962 swift::irgen::reemitAsUnsubstituted(swift::irgen::IRGenFunction&, swift::SILType, swift::SILType, swift::irgen::Explosion&, swift::irgen::Explosion&) + 658
8 swift 0x000000010c62ebd6 emitApplyArgument((anonymous namespace)::IRGenSILFunction&, swift::SILValue, swift::SILType, swift::irgen::Explosion&) + 294
9 swift 0x000000010c62dfa3 (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 2035
10 swift 0x000000010c616e92 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 7330
11 swift 0x000000010c614cfe swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 1358
12 swift 0x000000010c5306bb swift::irgen::IRGenerator::emitLazyDefinitions() + 987
13 swift 0x000000010c5f25d6 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) + 1350
14 swift 0x000000010c5f2b46 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, unsigned int, llvm::GlobalVariable**) + 86
15 swift 0x000000010c4b6825 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 12533
16 swift 0x000000010c4b2845 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3493
17 swift 0x000000010c474950 main + 3312
18 libdyld.dylib 0x00007fff6568b015 start + 1
1. While emitting IR SIL function "@_T07TestBug9SomeClassCAA10ObservableA2aDP11addObservery0G0QzFTW".
for 'addObserver(_:)' at /Users/iuliancorcoja/Desktop/TestBug/TestBug/TestBug/main.swift:19:2
The exact same code though, doesn't cause the compiler to crash in the latest Xcode (Xcode 9.3, Swift 4.1 Release). Instead, I get the following error when compiling:
Error
Type 'SomeClass' does not conform to protocol 'Observable' Possibly intended match 'SomeClass.Observer' (aka 'SomeDelegate & AnyObject') does not conform to 'AnyObject'
It doesn't really make sense since SomeClass.Observerdoes conform to AnyObject.
Remark
Changing the parameter in the addObserver(_:) method of the Observable protocol from Observer to anything else, e. g. AnyObject, doesn't throw any errors in Swift 4.0.3, but throws the same error as above in Swift 4.1
Error
Type 'SomeClass' does not conform to protocol 'Observable' Possibly intended match 'SomeClass.Observer' (aka 'SomeDelegate & AnyObject') does not conform to 'AnyObject'
@belkadan, I don't think these issues are related to each other. Even if I remove the "class" from "protocol SomeDelegate: class" the error still persists. Both Xcode and the compiler are clearly confused by the type composition:
Type 'SomeClass' does not conform to protocol 'Observable' Possibly intended match 'SomeClass.Observer' (aka 'SomeDelegate & AnyObject') does not conform to 'AnyObject'
A value of protocol type carries a payload together with a witness table. So it can be converted to a reference type via a representation change, but it is not directly usable as one. This is why you cannot bind a protocol type to a generic parameter that is class constrained.
This is more of an implementation restriction than a language design decision, but it is difficult to change now so we are probably stuck with it.
SR-55 probably has a few too many things dup'd to it, but the error is correct in the current Swift, if poorly phrased.
Attachment: Download
Environment
System Version: macOS 10.13.4 (17E199)
Model Name: MacBook Pro
Model Identifier: MacBookPro11,5
Xcode 9.2:
Version: 9.2
Obtained from: Apple
Xcode:
Version: 9.3
Obtained from: Mac App Store
Additional Detail from JIRA
md5: 88a96e0fa13427206c7a2339f609d60d
duplicates:
Issue Description:
Summary
Within Xcode (or Playground), when creating a new class which conforms to a generic protocol with
associatedtype
with a type constraint, defining thetypealias
with a protocol composition causes the compiler to crash.I couldn't reproduce this in REPL (see attached screenshot).
How to reproduce?
Tested with Xcode 9.2, i. e. toolchain for Swift 4.0.3 Release
Error
Command failed due to signal: Abort trap: 6
Stack Trace
The exact same code though, doesn't cause the compiler to crash in the latest Xcode (Xcode 9.3, Swift 4.1 Release). Instead, I get the following error when compiling:
Error
Type 'SomeClass' does not conform to protocol 'Observable'
Possibly intended match 'SomeClass.Observer' (aka 'SomeDelegate & AnyObject') does not conform to 'AnyObject'
It doesn't really make sense since
SomeClass.Observer
does conform toAnyObject
.Remark
Changing the parameter in the
addObserver(_:
) method of theObservable
protocol fromObserver
to anything else, e. g.AnyObject
, doesn't throw any errors in Swift 4.0.3, but throws the same error as above in Swift 4.1Error
Type 'SomeClass' does not conform to protocol 'Observable'
Possibly intended match 'SomeClass.Observer' (aka 'SomeDelegate & AnyObject') does not conform to 'AnyObject'
Code
The text was updated successfully, but these errors were encountered: