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-2349] Segfault while type-checking expression in which [AnyHashable: Any] cannot be converted to [String: String] #44956

Closed
swift-ci opened this issue Aug 16, 2016 · 5 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

@swift-ci
Copy link
Collaborator

Previous ID SR-2349
Radar rdar://problem/27869032
Original Reporter rydermackay (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

Xcode 8.0 beta 6 (8S201h)

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

md5: 1b51ef917951912c9069f15781f81271

duplicates:

  • SR-2288 8/4 Snapshot Assertion Failure

relates to:

  • SR-2288 8/4 Snapshot Assertion Failure

Issue Description:

Attempting to compile a source file (in Xcode or on the command line) with the following global functions:

func foo(_ array: [Any]) -> [AnyHashable: Any] {
    return [:]
}

func useFoo() {
    let array: [String] = []
    foo(array) as? [String: String]
}

Crashes with the following stack trace:

$ swiftc crash.swift
0  swift                    0x000000010b5b799d PrintStackTraceSignalHandler(void*) + 45
1  swift                    0x000000010b5b73e6 SignalHandler(int) + 470
2  libsystem_platform.dylib 0x00007fff9195252a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff5729fd40 _sigtramp + 3314866224
4  swift                    0x00000001091b0e8f std::__1::__function::__func<(anonymous namespace)::FailureDiagnosis::visitExpr(swift::Expr*)::$_14, std::__1::allocator<(anonymous namespace)::FailureDiagnosis::visitExpr(swift::Expr*)::$_14>, swift::Expr* (swift::Expr*)>::operator()(swift::Expr*&&) + 47
5  swift                    0x00000001093ac316 swift::Expr::forEachImmediateChildExpr(std::__1::function<swift::Expr* (swift::Expr*)> const&)::ChildWalker::walkToExprPre(swift::Expr*) + 38
6  swift                    0x0000000109328aee swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 7790
7  swift                    0x000000010918dd2e swift::ASTVisitor<(anonymous namespace)::FailureDiagnosis, bool, void, void, void, void, void>::visit(swift::Expr*) + 254
8  swift                    0x00000001091885a2 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 82
9  swift                    0x00000001091b1fbf swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 4367
10 swift                    0x000000010922b555 swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 1157
11 swift                    0x000000010922dca0 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 736
12 swift                    0x00000001092ae4c8 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 488
13 swift                    0x00000001092ad4bd swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, swift::SourceLoc) + 365
14 swift                    0x00000001092b1bfc swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 188
15 swift                    0x0000000109266caa swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) + 6714
16 swift                    0x0000000108f1dcbf swift::CompilerInstance::performSema() + 5199
17 swift                    0x00000001089cb06d performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 2765
18 swift                    0x00000001089c82c5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17029
19 swift                    0x000000010898588d main + 8685
20 libdyld.dylib            0x00007fff94e9a5ad start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file crash.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name crash -o /var/folders/vw/1y9kqkx12lz087vl48vvbg9r0000gp/T/crash-24deda.o 
1.  While type-checking 'useFoo' at crash.swift:5:1
2.  While type-checking expression at [crash.swift:7:5 - line:7:35] RangeText="foo(array) as? [String: String]"
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)

To reproduce, compile the attached crash.swift file.

If I call foo with an array literal or an Array<Any> rather than Array<String>, I get the expected diagnostic:

crash.swift:6:5: error: '[AnyHashable : Any]' is not convertible to '[String : String]'
    foo([]) as? [String: String]
    ^~~~~~~
@belkadan
Copy link
Contributor

cc @jckarter

@belkadan
Copy link
Contributor

Same assertion failure as SR-2288, possibly related?

@rudkx
Copy link
Member

rudkx commented Aug 16, 2016

It's the same issue. If we emit a diagnostic in the context of a collection conversion, we crash.

@jckarter
Copy link
Member

There shouldn't be a diagnostic, since [String] ought to be a subtype of [Any], and [AnyHashable: Any] ought to be castable to [String: String]. cc @rjmccall

@rudkx
Copy link
Member

rudkx commented Aug 17, 2016

@jckarter Yes, good point!

Now that you've opened a separate issue for the fact that the cast should be permitted, I'll just dup this issue to the other one about the crash during diagnostic emission.

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

No branches or pull requests

5 participants