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-4888] Crash: Tuple KeyPaths #47465
Comments
@swift-ci create |
Merged. Support for tuple elements will have to wait for another time, but the compiler shouldn't crash anymore. Thanks! |
I'm seeing this again in the current Xcode 9 beta 6. The only difference is that I'm using a struct Container {
typealias Element = (name: String, count: Int)
let elem: Element? = (name: "test", count: 2)
}
let keyPath: KeyPath<Container, String> = \Container.elem?.0
let keyPath: KeyPath<Container, String> = \Container.elem?.name When compiling, Swift fails with a Segfault 11: 0 swift 0x000000011133942a PrintStackTraceSignalHandler(void*) + 42
1 swift 0x0000000111338866 SignalHandler(int) + 662
2 libsystem_platform.dylib 0x00007fff983c6b3a _sigtramp + 26
3 swift 0x000000010ef16164 swift::Type::transformRec(llvm::function_ref<llvm::Optional<swift::Type> (swift::TypeBase*)>) const + 148
4 swift 0x000000010ec34869 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 25
5 swift 0x000000010ed50f44 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1540
6 swift 0x000000010ec5d52b (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<TCCFlags, unsigned int>, swift::ExprTypeCheckListener*, bool) + 1963
7 swift 0x000000010ec56076 (anonymous namespace)::FailureDiagnosis::diagnoseContextualConversionError(swift::Expr*, swift::Type) + 86
8 swift 0x000000010ec4da05 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 101
9 swift 0x000000010ec837f7 swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 6199
10 swift 0x000000010ed507a1 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>) + 8353
11 swift 0x000000010ed50c1d swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 733
12 swift 0x000000010ed53e1e swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*, bool) + 366
13 swift 0x000000010ed543dc swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 188
14 swift 0x000000010ed671d5 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 1349
15 swift 0x000000010edd64ad swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 13805
16 swift 0x000000010edd8fdc swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 220
17 swift 0x000000010edf56a5 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 1861
18 swift 0x000000010e926144 swift::CompilerInstance::performSema() + 4628
19 swift 0x000000010dcaaa62 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1378
20 swift 0x000000010dca8c94 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7716
21 swift 0x000000010dc5dbb8 main + 12248
22 libdyld.dylib 0x00007fff981b7235 start + 1
23 libdyld.dylib 0x000000000000000a start + 1743031766
Stack dump:
0. Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret s4_keypath_tuple.swift -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name s4_keypath_tuple
1. While type-checking declaration 0x7ff386859398 at s4_keypath_tuple.swift:7:1
2. While type-checking expression at [s4_keypath_tuple.swift:7:43 - line:7:60] RangeText="\Container.elem?.0"
3. While type-checking expression at [s4_keypath_tuple.swift:7:43 - line:7:60] RangeText="\Container.elem?.0" $ swift --version
Apple Swift version 4.0 (swiftlang-900.0.63.10 clang-900.0.36)
Target: x86_64-apple-macosx10.9 |
@swift-ci create |
Both the code snippets of @stephencelis and @ffried do not crash the compiler using Swift version 5.3 (swiftlang-1200.0.22.4 clang-1200.0.25.1). A quick note on @ffried's example:
In order to return let keyPath: KeyPath<Container, String> = \Container.elem!.0
let keyPath: KeyPath<Container, String> = \Container.elem!.name |
@xAlien95 Thanks. Yea, the KeyPath Value should be |
Should this be marked as resolved/closed now? |
Fixed. |
Environment
Swift Development Snapshot 2017-05-12 (a)
Xcode 8.3.2
macOS 10.12.5 Beta (16F71b)
Additional Detail from JIRA
md5: e43e68b9511248f280cf77762db2a6d0
Issue Description:
Right now, tuple KeyPaths crash the compiler.
Basic case:
Ideally the KeyPath works in a read-only fashion! Less ideally we get a compiler error.
The text was updated successfully, but these errors were encountered: