Skip to content
New issue

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

[SR-8813] Using implicit associatedtype in a stored property defined by typealias segfaults the compiler #51321

Closed
ffried opened this issue Sep 21, 2018 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@ffried
Copy link
Contributor

ffried commented Sep 21, 2018

Previous ID SR-8813
Radar rdar://problem/44680996
Original Reporter @ffried
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment
Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.0.0 

Also happens with Swift 4.1 in Xcode 9.4.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @gregomni
Priority Medium

md5: 6a8ac680b1324b94892261f00ceb0509

relates to:

  • SR-5546 Assertion failed: (isa(Val) && "cast() argument of incompatible type!")

Issue Description:

The following code segfaults the compiler:

protocol BaseProtocol {
   associatedtype Value
   typealias Closure = () -> Value

   init(closure: @escaping Closure)
}

struct Base<Value>: BaseProtocol {
   private let closure: Closure

   init(closure: @escaping Closure) {
      self.closure = closure
   }
}

Note that just declaring the property is not enough. The initializer is necessary as well.

There are two workarounds:

  • Explicitly define the typealias Value = Val (assuming the generic parameter is named Val instead of Value)

  • Changing the property declaration to let closure: () -> Value.

Segfault stack trace:

$ swift s42_protocolTypealias.swift 
0  swift                    0x000000010e44464a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010e443dfe SignalHandler(int) + 302
2  libsystem_platform.dylib 0x00007fff664a6b3d _sigtramp + 29
3  libsystem_platform.dylib 0xfd00000070001004 _sigtramp + 162899172
4  swift                    0x000000010b5baecd swift::Lowering::TypeConverter::getConstantInfo(swift::SILDeclRef) + 61
5  swift                    0x000000010b5e02ae swift::SILModule::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, swift::ProfileCounter) + 94
6  swift                    0x000000010b044912 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 338
7  swift                    0x000000010b048215 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 1717
8  swift                    0x000000010b135022 (anonymous namespace)::SILGenType::emitType() + 706
9  swift                    0x000000010b050ff9 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 73
10 swift                    0x000000010b05001b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 939
11 swift                    0x000000010b051c22 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool) + 1410
12 swift                    0x000000010a6d374e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 29838
13 swift                    0x000000010a6c8dc5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7717
14 swift                    0x000000010a66ea35 main + 1349
15 libdyld.dylib            0x00007fff662bd085 start + 1
16 libdyld.dylib            0x000000000000000a start + 2580819846
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret s42_protocolTypealias.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name s42_protocolTypealias 
@belkadan
Copy link
Contributor

With asserts:

checked decl cannot have error type
(parameter "closure" apiName=closure type='<<error type>>' interface type='<<error type>>')

1. While walking into decl 'Base' at <stdin>:8:1
2. While walking into body of 'init(closure:)' at <stdin>:11:4
3. While verifying VarDecl 'closure' at <stdin>:11:9

@swift-ci create

@gregomni
Copy link
Collaborator

Fix for this also fixes SR-5546

@gregomni
Copy link
Collaborator

#19830

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants