swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.31k stars 10.34k forks source link

Assertion failed: getFromType()->is<AnyFunctionType>() && getToType()->is<AnyFunctionType>(), file S:\SourceCache\swift-project\swift\lib\Sema\CSDiagnostics.h, line 1043 #66003

Open compnerd opened 1 year ago

compnerd commented 1 year ago
import WinSDK

public func f() {
    let callback: (@convention(c) (HWND, LPARAM) -> Bool)? = { _,_ in true }
    EnumWindows(callback, 0)
}
Assertion failed: getFromType()->is<AnyFunctionType>() && getToType()->is<AnyFunctionType>(), file S:\SourceCache\swift-project\swift\lib\Sema\CSDiagnostics.h, line 1043
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: S:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\bin\\swift-frontend.exe -frontend -c -primary-file reduced.swift -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk S:\\Library\\Developer\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk -color-diagnostics -empty-abi-descriptor -plugin-path S:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift\\host\\plugins -plugin-path S:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\local\\lib\\swift\\host\\plugins -resource-dir S:\\Library\\Developer\\Toolchains\\unknown-Asserts-development.xctoolchain\\usr\\lib\\swift -module-name NUL -o NUL
1.      Swift version 5.9-dev (LLVM 25f46a8a26f5d3c, Swift 9ca8a0e6e374b79)
2.      Compiling with the current language version
3.      While evaluating request TypeCheckSourceFileRequest(source_file "reduced.swift")
4.      While evaluating request TypeCheckFunctionBodyRequest(NUL.(file).f()@reduced.swift:3:13)
5.      While type-checking statement at [reduced.swift:3:17 - line:6:1] RangeText="{
    let callback: (@convention(c) (HWND, LPARAM) -> Bool)? = { _,_ in true }
    EnumWindows(callback, 0)
"
6.      While type-checking expression at [reduced.swift:5:5 - line:5:28] RangeText="EnumWindows(callback, 0"
7.      While type-checking-target starting at reduced.swift:5:5
Exception Code: 0x80000003
 #0 0x00007ff7456dc055 HandleAbort S:\SourceCache\swift-project\llvm-project\llvm\lib\Support\Windows\Signals.inc:414:0
 #1 0x00007ffd1a21e5f5 (C:\Windows\System32\ucrtbase.dll+0x7e5f5)
 #2 0x00007ffd1a21f601 (C:\Windows\System32\ucrtbase.dll+0x7f601)
 #3 0x00007ffd1a22106a (C:\Windows\System32\ucrtbase.dll+0x8106a)
 #4 0x00007ffd1a220f5d (C:\Windows\System32\ucrtbase.dll+0x80f5d)
 #5 0x00007ffd1a2211f1 (C:\Windows\System32\ucrtbase.dll+0x811f1)
 #6 0x00007ff7414ca7af swift::constraints::FunctionTypeMismatch::FunctionTypeMismatch(class swift::constraints::Solution const &, enum swift::ContextualTypePurpose, class swift::Type, class swift::Type, class llvm::ArrayRef<unsigned int>, class swift::constraints::ConstraintLocator *) S:\SourceCache\swift-project\swift\lib\Sema\CSDiagnostics.h:1044:0
 #7 0x00007ff7414cd239 swift::constraints::AllowFunctionTypeMismatch::coalesceAndDiagnose(class swift::constraints::Solution const &, class llvm::ArrayRef<class swift::constraints::ConstraintFix *>, bool) const S:\SourceCache\swift-project\swift\lib\Sema\CSFix.cpp:669:0
 #8 0x00007ff7413d7e7d swift::constraints::ConstraintFix::isFatal S:\SourceCache\swift-project\swift\include\swift\Sema\CSFix.h:483:0
 #9 0x00007ff7413d7e7d swift::constraints::ConstraintSystem::applySolutionFixes(class swift::constraints::Solution const &) S:\SourceCache\swift-project\swift\lib\Sema\CSApply.cpp:8837:0
#10 0x00007ff7413d6d75 swift::constraints::ConstraintSystem::applySolution(class swift::constraints::Solution &, class swift::constraints::SyntacticElementTarget) S:\SourceCache\swift-project\swift\lib\Sema\CSApply.cpp:9567:0
#11 0x00007ff7413b5b12 swift::TypeChecker::typeCheckTarget(class swift::constraints::SyntacticElementTarget &, class swift::OptionSet<enum swift::TypeCheckExprFlags, unsigned int>) S:\SourceCache\swift-project\swift\lib\Sema\TypeCheckConstraints.cpp:483:0
#12 0x00007ff7413b40a9 swift::TypeChecker::typeCheckExpression(class swift::constraints::SyntacticElementTarget &, class swift::OptionSet<enum swift::TypeCheckExprFlags, unsigned int>) S:\SourceCache\swift-project\swift\lib\Sema\TypeCheckConstraints.cpp:412:0
#13 0x00007ff7413b4151 swift::TypeChecker::typeCheckExpression(class swift::Expr *&, class swift::DeclContext *, struct swift::constraints::ContextualTypeInfo, class swift::OptionSet<enum swift::TypeCheckExprFlags, unsigned int>) S:\SourceCache\swift-project\swift\lib\Sema\TypeCheckConstraints.cpp:391:0
#14 0x00007ff7412d477a `anonymous namespace'::StmtChecker::typeCheckASTNode S:\SourceCache\swift-project\swift\lib\Sema\TypeCheckStmt.cpp:2033:0
#15 0x00007ff7412d5a2d `anonymous namespace'::StmtChecker::visitBraceStmt S:\SourceCache\swift-project\swift\lib\Sema\TypeCheckStmt.cpp:2093:0
#16 0x00007ff7412cb5d3 `anonymous namespace'::StmtChecker::typeCheckStmt<swift::BraceStmt> S:\SourceCache\swift-project\swift\lib\Sema\TypeCheckStmt.cpp:1034:0
#17 0x00007ff7412d0e78 swift::TypeCheckFunctionBodyRequest::evaluate(class swift::Evaluator &, class swift::AbstractFunctionDecl *) const S:\SourceCache\swift-project\swift\lib\Sema\TypeCheckStmt.cpp:2717:0
#18 0x00007ff74184ceba swift::Evaluator::getResultUncached<class swift::TypeCheckFunctionBodyRequest>(class swift::TypeCheckFunctionBodyRequest const &) S:\SourceCache\swift-project\swift\include\swift\AST\Evaluator.h:388:0
#19 0x00007ff7418385d7 swift::Evaluator::getResultCached<class swift::TypeCheckFunctionBodyRequest, 0>(class swift::TypeCheckFunctionBodyRequest const &) S:\SourceCache\swift-project\swift\include\swift\AST\Evaluator.h:418:0
#20 0x00007ff741825c93 swift::evaluateOrDefault<class swift::TypeCheckFunctionBodyRequest>(class swift::Evaluator &, class swift::TypeCheckFunctionBodyRequest, class swift::BraceStmt *) S:\SourceCache\swift-project\swift\include\swift\AST\Evaluator.h:106:0
#21 0x00007ff741897568 swift::AbstractFunctionDecl::getTypecheckedBody(void) const S:\SourceCache\swift-project\swift\lib\AST\Decl.cpp:8573:0
#22 0x00007ff74119df21 swift::TypeCheckSourceFileRequest::evaluate(class swift::Evaluator &, class swift::SourceFile *) const S:\SourceCache\swift-project\swift\lib\Sema\TypeChecker.cpp:300:0
#23 0x00007ff74117bc1a swift::SimpleRequest<class swift::TypeCheckSourceFileRequest, (class swift::SourceFile *), 12>::evaluateRequest(class swift::TypeCheckSourceFileRequest const &, class swift::Evaluator &) S:\SourceCache\swift-project\swift\include\swift\AST\SimpleRequest.h:290:0
#24 0x00007ff741197d48 swift::Evaluator::getResultUncached<class swift::TypeCheckSourceFileRequest>(class swift::TypeCheckSourceFileRequest const &) S:\SourceCache\swift-project\swift\include\swift\AST\Evaluator.h:388:0
#25 0x00007ff74119629c swift::Evaluator::getResultCached<class swift::TypeCheckSourceFileRequest, 0>(class swift::TypeCheckSourceFileRequest const &) S:\SourceCache\swift-project\swift\include\swift\AST\Evaluator.h:418:0
#26 0x00007ff741194246 swift::evaluateOrDefault<class swift::TypeCheckSourceFileRequest>(class swift::Evaluator &, class swift::TypeCheckSourceFileRequest, class std::tuple<>) S:\SourceCache\swift-project\swift\include\swift\AST\Evaluator.h:106:0
#27 0x00007ff7411a1d4a swift::performTypeChecking(class swift::SourceFile &) S:\SourceCache\swift-project\swift\lib\Sema\TypeChecker.cpp:260:0
#28 0x00007ff74031acdc llvm::function_ref<bool __cdecl(swift::SourceFile &)>::callback_fn<`swift::CompilerInstance::performSema'::`2'::<lambda_1> > S:\SourceCache\swift-project\llvm-project\llvm\include\llvm\ADT\STLFunctionalExtras.h:45:0
#29 0x00007ff7403220de swift::CompilerInstance::forEachFileToTypeCheck(class llvm::function_ref<(class swift::SourceFile &)>) S:\SourceCache\swift-project\swift\lib\Frontend\Frontend.cpp:1460:0
#30 0x00007ff740327625 swift::CompilerInstance::performSema(void) S:\SourceCache\swift-project\swift\lib\Frontend\Frontend.cpp:1385:0
#31 0x00007ff74011fe77 performAction S:\SourceCache\swift-project\swift\lib\FrontendTool\FrontendTool.cpp:1381:0
#32 0x00007ff74012032b std::unique_ptr<swift::ASTContext,std::default_delete<swift::ASTContext> >::operator bool C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.35.32215\include\memory:3202:0
#33 0x00007ff74012032b std::operator== C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.35.32215\include\memory:3478:0
#34 0x00007ff74012032b std::operator!= C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.35.32215\include\memory:3489:0
#35 0x00007ff74012032b swift::CompilerInstance::hasASTContext S:\SourceCache\swift-project\swift\include\swift\Frontend\Frontend.h:560:0
#36 0x00007ff74012032b performCompile S:\SourceCache\swift-project\swift\lib\FrontendTool\FrontendTool.cpp:1416:0
#37 0x00007ff740122941 swift::performFrontend(class llvm::ArrayRef<char const *>, char const *, void *, class swift::FrontendObserver *) S:\SourceCache\swift-project\swift\lib\FrontendTool\FrontendTool.cpp:2355:0
#38 0x00007ff73ffa9c66 run_driver S:\SourceCache\swift-project\swift\lib\DriverTool\driver.cpp:235:0
#39 0x00007ff73ffa9679 swift::mainEntry(int, char const **) S:\SourceCache\swift-project\swift\lib\DriverTool\driver.cpp:498:0
#40 0x00007ff74576772c invoke_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78:0
#41 0x00007ff74576772c __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#42 0x00007ffd1b7c26ad (C:\Windows\System32\KERNEL32.DLL+0x126ad)
#43 0x00007ffd1c86a9f8 (C:\Windows\SYSTEM32\ntdll.dll+0x5a9f8)
compnerd commented 1 year ago

This should be possible to reproduce on other platforms by just creating the appropriate typedefs in a C module.

xedin commented 1 year ago

Could you please specify here how HWND and HWND so possible contributors don't have to dig through WinSDK to find them?

compnerd commented 1 year ago

@xedin sure!

struct __HWND;
typedef struct __HWND *HWND;
typedef unsigned long long LPARAM;
typedef CHAR BOOL;

Note that the raw signature uses a BOOL which has special handling via the compiler for transforming through WindowsBool, similar to how Darwin handles the conversion for Cocoa.

xedin commented 1 year ago

Thank you!