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-13064] Void closure crash with Swift 5.3 #55510

Open
keith opened this issue Jun 23, 2020 · 3 comments
Open

[SR-13064] Void closure crash with Swift 5.3 #55510

keith opened this issue Jun 23, 2020 · 3 comments
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 type checker Area → compiler: Semantic analysis

Comments

@keith
Copy link
Collaborator

keith commented Jun 23, 2020

Previous ID SR-13064
Radar None
Original Reporter @keith
Type Bug
Environment

Xcode 12 beta 1 Swift 5.3

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

md5: 601384b2b2e9ca949011a4a8a15a8dc0

Issue Description:

Compiling this code:

class A {
    init(completion: ((Void) -> Void)?) {}
}

class B: A {
    init(completion: (() -> Void)?) {
        super.init(completion: completion ?? {})
    }
}

With `swift foo.swift` causes this crash:

fromType->getCanonicalType() = (bound_generic_enum_type decl=Swift.(file).Optional
  (function_type escaping
    (input=function_params num_params=0)
    (output=tuple_type num_elements=0)))
toType->getCanonicalType() = (bound_generic_enum_type decl=Swift.(file).Optional
  (function_type escaping
    (input=function_params num_params=1
      (param
        (tuple_type num_elements=0)))
    (output=tuple_type num_elements=0)))
Stack dump:
0.      Program arguments: /Applications/Xcode-12.0.0-beta1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret foo.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode-12.0.0-beta1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.16.sdk -color-diagnostics -target-sdk-version 10.16 -module-name foo
1.      Apple Swift version 5.3 (swiftlang-1200.0.16.9 clang-1200.0.22.5)
2.      While evaluating request TypeCheckSourceFileRequest(source_file "foo.swift")
3.      While evaluating request TypeCheckFunctionBodyUntilRequest(foo.(file).B.init(completion:)@foo.swift:6:5, )
4.      While type-checking statement at [foo.swift:6:37 - line:8:5] RangeText="{
        super.init(completion: completion ?? {})
    "
5.      While type-checking expression at [foo.swift:7:9 - line:7:48] RangeText="super.init(completion: completion ?? {}"
0  swift                    0x000000010478af65 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000104789f65 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000010478b51f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff70dc25fd _sigtramp + 29
4  libsystem_malloc.dylib   0x00007fff70d852d6 tiny_free_no_lock + 1111
5  swift                    0x0000000100fea78f (anonymous namespace)::ExprRewriter::coerceCallArguments(swift::Expr*, swift::AnyFunctionType*, swift::ConcreteDeclRef, swift::ApplyExpr*, llvm::ArrayRef<swift::Identifier>, bool, swift::constraints::ConstraintLocatorBuilder) + 4191
6  swift                    0x0000000100fe8933 (anonymous namespace)::ExprRewriter::finishApply(swift::ApplyExpr*, swift::Type, swift::constraints::ConstraintLocatorBuilder, swift::constraints::ConstraintLocatorBuilder) + 12067
7  swift                    0x0000000100ff277d (anonymous namespace)::ExprRewriter::visitApplyExpr(swift::ApplyExpr*) + 477
8  swift                    0x0000000100fcafb2 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 18
9  swift                    0x00000001014df7f4 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 164
10 swift                    0x0000000100fc1664 (anonymous namespace)::ExprWalker::rewriteTarget(swift::constraints::SolutionApplicationTarget) + 324
11 swift                    0x0000000100fc1380 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SolutionApplicationTarget) + 6928
12 swift                    0x00000001011a81cb swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, bool&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 1307
13 swift                    0x00000001011a7bf8 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 360
14 swift                    0x000000010128d4cb swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 9115
15 swift                    0x0000000101288c7a bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 314
16 swift                    0x000000010128754e swift::TypeCheckFunctionBodyUntilRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*, swift::SourceLoc) const + 2398
17 swift                    0x00000001012904fd llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckFunctionBodyUntilRequest, (void*)0>(swift::TypeCheckFunctionBodyUntilRequest const&) + 925
18 swift                    0x00000001012886c8 swift::TypeCheckFunctionBodyUntilRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyUntilRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyUntilRequest, swift::TypeCheckFunctionBodyUntilRequest::OutputType) + 440
19 swift                    0x00000001012c5db4 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 1252
20 swift                    0x00000001012c89c9 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 953
21 swift                    0x00000001012c5744 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 164
22 swift                    0x0000000100448c47 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 6439
23 swift                    0x000000010030aee1 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6849
24 swift                    0x000000010028fa97 main + 1255
25 libdyld.dylib            0x00007fff70bc9cc9 start + 1
26 libdyld.dylib            0x000000000000000d start + 18446603338624754501
zsh: illegal hardware instruction  PATH="/usr/bin:/bin" swift foo.swift
@theblixguy
Copy link
Collaborator

Reproduced on master as well. I suppose you meant completion's type in A.init to be (() -> Void)? instead?

@keith
Copy link
Collaborator Author

keith commented Jun 24, 2020

In our actual case the hierarchy is more complicated and the `Void` there is actually a generic's associatedType which can be set to `Void`. But another workaround is to do:

let completion = completion ?? {}
super.init(completion: completion)

Which is what we've applied for now

@LucianoPAlmeida
Copy link
Collaborator

This seems to be fixed on main now

@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
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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants