Skip to content

This complicated combination of trailing closures and autoclosures crashes the Swift compiler #74645

Open
@schuelermine

Description

@schuelermine

Description

No response

Reproduction

func foo(x: @autoclosure () -> () = (), _ y: @autoclosure () -> (), z: @autoclosure () -> (), w: () -> ()) { }

foo(x: ()) { } z: { } w: { }

Stack dump

Planning build
Building for debugging...
Write auxiliary file /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift-version-575752FA6EFF9271.txt
/opt/swift-5.10.1/bin/swiftc -module-name swift_crash -emit-dependencies -emit-module -emit-module-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.swiftmodule -output-file-map /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.build/output-file-map.json -incremental -c @/home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.build/sources -I /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug -target x86_64-unknown-linux-gnu -swift-version 5 -v -enable-batch-mode -index-store-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/index/store -Onone -enable-testing -j16 -DSWIFT_PACKAGE -DDEBUG -module-cache-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/ModuleCache -parseable-output -Xfrontend -entry-point-function-name -Xfrontend swift_crash_main -g -Xcc -fPIC -Xcc -g -package-name swift_crash -Xcc -fno-omit-frame-pointer
Swift version 5.10.1 (swift-5.10.1-RELEASE)
Target: x86_64-unknown-linux-gnu
/opt/swift-5.10.1/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types /home/ubuntu/Documents/swift-crash/Sources/main.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -I /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug -enable-testing -g -module-cache-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /opt/swift-5.10.1/bin/swift-driver -entry-point-function-name swift_crash_main -empty-abi-descriptor -resource-dir /opt/swift-5.10.1/lib/swift -enable-anonymous-context-mangled-names -Xcc -fPIC -Xcc -g -Xcc -fno-omit-frame-pointer -module-name swift_crash -package-name swift_crash -plugin-path /opt/swift-5.10.1/lib/swift/host/plugins -plugin-path /opt/swift-5.10.1/local/lib/swift/host/plugins -emit-module-doc-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.swiftdoc -emit-module-source-info-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.swiftsourceinfo -emit-dependencies-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.build/swift_crash.emit-module.d -o /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.swiftmodule
/opt/swift-5.10.1/bin/swift-frontend -frontend -c -primary-file /home/ubuntu/Documents/swift-crash/Sources/main.swift -emit-dependencies-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.build/main.d -emit-reference-dependencies-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.build/main.swiftdeps -target x86_64-unknown-linux-gnu -disable-objc-interop -I /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug -enable-testing -g -module-cache-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /opt/swift-5.10.1/bin/swift-driver -entry-point-function-name swift_crash_main -empty-abi-descriptor -resource-dir /opt/swift-5.10.1/lib/swift -enable-anonymous-context-mangled-names -Xcc -fPIC -Xcc -g -Xcc -fno-omit-frame-pointer -module-name swift_crash -package-name swift_crash -plugin-path /opt/swift-5.10.1/lib/swift/host/plugins -plugin-path /opt/swift-5.10.1/local/lib/swift/host/plugins -o /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.build/main.swift.o -index-store-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/index/store -index-system-modules
error: compile command failed due to signal 6 (use -v to see invocation)
swift-frontend: /home/build-user/swift/lib/Sema/MiscDiagnostics.cpp:2154: bool swift::diagnoseArgumentLabelError(ASTContext &, const ArgumentList *, ArrayRef<Identifier>, ParameterContext, InFlightDiagnostic *): Assertion `numMissing > 0 || numExtra > 0 || numWrong > 0' failed.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /opt/swift-5.10.1/bin/swift-frontend -frontend -c -primary-file /home/ubuntu/Documents/swift-crash/Sources/main.swift -emit-dependencies-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.build/main.d -emit-reference-dependencies-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.build/main.swiftdeps -target x86_64-unknown-linux-gnu -disable-objc-interop -I /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug -enable-testing -g -module-cache-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /opt/swift-5.10.1/bin/swift-driver -entry-point-function-name swift_crash_main -empty-abi-descriptor -resource-dir /opt/swift-5.10.1/lib/swift -enable-anonymous-context-mangled-names -Xcc -fPIC -Xcc -g -Xcc -fno-omit-frame-pointer -module-name swift_crash -package-name swift_crash -plugin-path /opt/swift-5.10.1/lib/swift/host/plugins -plugin-path /opt/swift-5.10.1/local/lib/swift/host/plugins -o /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/swift_crash.build/main.swift.o -index-store-path /home/ubuntu/Documents/swift-crash/.build/x86_64-unknown-linux-gnu/debug/index/store -index-system-modules
1.	Swift version 5.10.1 (swift-5.10.1-RELEASE)
2.	Compiling with the current language version
3.	While evaluating request TypeCheckSourceFileRequest(source_file "/home/ubuntu/Documents/swift-crash/Sources/main.swift")
4.	While type-checking statement at [/home/ubuntu/Documents/swift-crash/Sources/main.swift:3:1 - line:3:28] RangeText="foo(x: ()) { } z: { } w: { "
5.	While type-checking expression at [/home/ubuntu/Documents/swift-crash/Sources/main.swift:3:1 - line:3:28] RangeText="foo(x: ()) { } z: { } w: { "
6.	While type-checking-target starting at /home/ubuntu/Documents/swift-crash/Sources/main.swift:3:1
 #0 0x00005640c43dffe4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/swift-5.10.1/bin/swift-frontend+0x72effe4)
 #1 0x00005640c43ddd4e llvm::sys::RunSignalHandlers() (/opt/swift-5.10.1/bin/swift-frontend+0x72edd4e)
 #2 0x00005640c43e0358 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f371e245320 (/lib/x86_64-linux-gnu/libc.so.6+0x45320)
 #4 0x00007f371e29eb1c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb1c)
 #5 0x00007f371e24526e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4526e)
 #6 0x00007f371e2288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
 #7 0x00007f371e22881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
 #8 0x00007f371e23b507 (/lib/x86_64-linux-gnu/libc.so.6+0x3b507)
 #9 0x00005640bf27df8d swift::diagnoseArgumentLabelError(swift::ASTContext&, swift::ArgumentList const*, llvm::ArrayRef<swift::Identifier>, swift::ParameterContext, swift::InFlightDiagnostic*) (/opt/swift-5.10.1/bin/swift-frontend+0x218df8d)
#10 0x00005640bf1d16cc swift::constraints::RelabelArguments::diagnose(swift::constraints::Solution const&, bool) const (/opt/swift-5.10.1/bin/swift-frontend+0x20e16cc)
#11 0x00005640bf48bd1f swift::constraints::ConstraintSystem::applySolutionFixes(swift::constraints::Solution const&) (/opt/swift-5.10.1/bin/swift-frontend+0x239bd1f)
#12 0x00005640bf48c5c9 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SyntacticElementTarget) (/opt/swift-5.10.1/bin/swift-frontend+0x239c5c9)
#13 0x00005640bf31c738 swift::TypeChecker::typeCheckTarget(swift::constraints::SyntacticElementTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) (/opt/swift-5.10.1/bin/swift-frontend+0x222c738)
#14 0x00005640bf31c56d swift::TypeChecker::typeCheckExpression(swift::constraints::SyntacticElementTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) (/opt/swift-5.10.1/bin/swift-frontend+0x222c56d)
#15 0x00005640bf31c454 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::constraints::ContextualTypeInfo, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) (/opt/swift-5.10.1/bin/swift-frontend+0x222c454)
#16 0x00005640bf42c143 (anonymous namespace)::StmtChecker::typeCheckASTNode(swift::ASTNode&) TypeCheckStmt.cpp:0:0
#17 0x00005640bf42fc2d swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) TypeCheckStmt.cpp:0:0
#18 0x00005640bf42dc6c bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) TypeCheckStmt.cpp:0:0
#19 0x00005640bf42dd01 swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) (/opt/swift-5.10.1/bin/swift-frontend+0x233dd01)
#20 0x00005640bf470062 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const (/opt/swift-5.10.1/bin/swift-frontend+0x2380062)
#21 0x00005640bf472734 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) crtstuff.c:0:0
#22 0x00005640bf4725be llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) crtstuff.c:0:0
#23 0x00005640bf46fea4 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) (/opt/swift-5.10.1/bin/swift-frontend+0x237fea4)
#24 0x00005640bf46fe84 swift::performTypeChecking(swift::SourceFile&) (/opt/swift-5.10.1/bin/swift-frontend+0x237fe84)
#25 0x00005640be1c9909 bool llvm::function_ref<bool (swift::SourceFile&)>::callback_fn<swift::CompilerInstance::performSema()::$_7>(long, swift::SourceFile&) Frontend.cpp:0:0
#26 0x00005640be1be43a swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<bool (swift::SourceFile&)>) (/opt/swift-5.10.1/bin/swift-frontend+0x10ce43a)
#27 0x00005640be1be39d swift::CompilerInstance::performSema() (/opt/swift-5.10.1/bin/swift-frontend+0x10ce39d)
#28 0x00005640bdf1ed12 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) FrontendTool.cpp:0:0
#29 0x00005640bdf0c51b performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#30 0x00005640bdf0af2f swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/opt/swift-5.10.1/bin/swift-frontend+0xe1af2f)
#31 0x00005640bddb0872 swift::mainEntry(int, char const**) (/opt/swift-5.10.1/bin/swift-frontend+0xcc0872)
#32 0x00007f371e22a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#33 0x00007f371e22a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#34 0x00005640bddaf855 _start (/opt/swift-5.10.1/bin/swift-frontend+0xcbf855)

Expected behavior

I don’t actually know if this program should be accepted or not.

Environment

Swift version 5.10.1 (swift-5.10.1-RELEASE)
Target: x86_64-unknown-linux-gnu

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    assertion failureBug → crash: An assertion failurebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.call expressionsFeature → expressions: Call expressionsclosuresFeature: closurescompilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareexpressionsFeature: expressionsregressionswift 6.0trailing closuresFeature: trailing closurestype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions