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-13442] Crash using unwrap (!) to refer to wrapped member on key path of optional root #55884

Closed
LucianoPAlmeida opened this issue Aug 25, 2020 · 3 comments

Comments

@LucianoPAlmeida
Copy link
Collaborator

@LucianoPAlmeida LucianoPAlmeida commented Aug 25, 2020

Previous ID SR-13442
Radar None
Original Reporter @LucianoPAlmeida
Type Bug
Status Closed
Resolution Done
Environment

Swift 5.3 Xcode 12 Beta 1

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

md5: ca2fc8d31331a56fdbd6606164c1a694

Issue Description:

Refering to wrapped members on a key path root inferred as optional using '?' works fine

func f<T>(_ x: KeyPath<String?, T>) -> T { "1"[keyPath: x] }

_ = f(\.?.count)
_ = f(\String?.?.count)

But using '!' crashes the compiler

Reproducer

func f<T>(_ x: KeyPath<String?, T>) -> T { "1"[keyPath: x] }

_ = f(\.!.count)
_ = f(\String?.!.count)

Stacktrace

1.  Apple Swift version 5.3 (swiftlang-1200.0.16.9 clang-1200.0.22.5)
2.  While evaluating request TypeCheckSourceFileRequest(source_file "/Users/lucianoalmeida/Documents/Programming/Test Area/swiftc/swiftc/main.swift")
3.  While type-checking statement at [/Users/lucianoalmeida/Documents/Programming/Test Area/swiftc/swiftc/main.swift:25:1 - line:25:23] RangeText="_ = f(\String?.!.count"
4.  While type-checking expression at [/Users/lucianoalmeida/Documents/Programming/Test Area/swiftc/swiftc/main.swift:25:1 - line:25:23] RangeText="_ = f(\String?.!.count"
0  swift                    0x0000000107fdef65 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000107fddf65 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000107fdf51f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff72d035fd _sigtramp + 29
4  swift                    0x0000000104eb1739 llvm::Optional<swift::Type> llvm::function_ref<llvm::Optional<swift::Type> (swift::TypeBase*)>::callback_fn<substType(swift::Type, llvm::function_ref<swift::Type (swift::SubstitutableType*)>, llvm::function_ref<swift::ProtocolConformanceRef (swift::CanType, swift::Type, swift::ProtocolDecl*)>, swift::SubstOptions)::$_25>(long, swift::TypeBase*) + 745
5  swift                    0x000000010484e3b0 (anonymous namespace)::SetExprTypes::walkToExprPost(swift::Expr*) + 688
6  swift                    0x0000000104d33879 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 297
7  swift                    0x0000000104d35db3 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 211
8  swift                    0x000000010483ca25 (anonymous namespace)::ExprRewriter::finishApply(swift::ApplyExpr*, swift::Type, swift::constraints::ConstraintLocatorBuilder, swift::constraints::ConstraintLocatorBuilder) + 12309
9  swift                    0x000000010484677d (anonymous namespace)::ExprRewriter::visitApplyExpr(swift::ApplyExpr*) + 477
10 swift                    0x000000010481efb2 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 18
11 swift                    0x0000000104d35161 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 6673
12 swift                    0x0000000104815664 (anonymous namespace)::ExprWalker::rewriteTarget(swift::constraints::SolutionApplicationTarget) + 324
13 swift                    0x0000000104815380 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SolutionApplicationTarget) + 6928
14 swift                    0x00000001049fc1cb swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, bool&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 1307
15 swift                    0x00000001049fbbf8 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 360
16 swift                    0x0000000104ae14cb swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 9115
17 swift                    0x0000000104adcc7a bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 314
18 swift                    0x0000000104adce45 swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 261
19 swift                    0x0000000104b19bb8 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 744
20 swift                    0x0000000104b1c9c9 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 953
21 swift                    0x0000000104b19744 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 164
22 swift                    0x0000000103c9cc47 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 6439
23 swift                    0x0000000103b5eee1 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6849
24 swift                    0x0000000103ae3a97 main + 1255
25 libdyld.dylib            0x00007fff72b0acc9 start + 1
26 libdyld.dylib            0x0000000000000050 start + 18446603338591982472
error: Segmentation fault: 11 (in target 'swiftc' from project 'swiftc')
@theblixguy
Copy link
Collaborator

@theblixguy theblixguy commented Aug 25, 2020

Looks like it is crashing in buildKeyPathOptionalForceComponent, probably because we don't have a key path component preceding the exclamation mark?

@LucianoPAlmeida
Copy link
Collaborator Author

@LucianoPAlmeida LucianoPAlmeida commented Aug 25, 2020

Humm, yeah I'm looking into this right now ... seems like we have to forward the component type, similar to what is done for OptionalChain, but I still have to test it

@LucianoPAlmeida
Copy link
Collaborator Author

@LucianoPAlmeida LucianoPAlmeida commented Aug 29, 2020

Fixed by #33623

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants