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-12626] Crash on apply KeyPathDynamicMemberLookup non WritableKeyPath to a set subscript #55070

Closed
LucianoPAlmeida opened this issue Apr 19, 2020 · 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

@LucianoPAlmeida
Copy link
Collaborator

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

Xcode 11.4 Swift 5.2

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

md5: 1a94b72d7a4a070413f1c1951632f380

Issue Description:

Applying a non WritableKeyPath to a set subscript crashes the compiler

@dynamicMemberLookup
struct S {
  var i: Int

  subscript(dynamicMember member: KeyPath<S, Int>) -> Int {
    get { self[keyPath: member] }
    set { self[keyPath: member] = newValue } // Crash on buildKeyPathDynamicMemberIndexExpr
  }
}

Changing the parameter to WritableKeyPath works just fine.

Stacktrace

0  swift                    0x00000001078884ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000107887cc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6c8a65fd _sigtramp + 29
3  libsystem_platform.dylib 0x0000000109065a00 _sigtramp + 2625369120
4  swift                    0x000000010401e775 (anonymous namespace)::ExprRewriter::buildKeyPathDynamicMemberIndexExpr(swift::BoundGenericType*, swift::SourceLoc, swift::constraints::ConstraintLocator*) + 2645
5  swift                    0x0000000104013288 (anonymous namespace)::ExprRewriter::buildDynamicMemberLookupRef(swift::Expr*, swift::Expr*, swift::SourceLoc, swift::SourceLoc, swift::constraints::SelectedOverload const&, swift::constraints::ConstraintLocator*) + 568
6  swift                    0x000000010400207c swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) + 7948
7  swift                    0x00000001040000b2 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 18
8  swift                    0x00000001045b3419 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 4041
9  swift                    0x0000000103ff6a63 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool) + 7139
10 swift                    0x00000001041b9ac9 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 1033
11 swift                    0x00000001042888e5 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 7893
12 swift                    0x00000001042863a9 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 121
13 swift                    0x000000010427e2ff swift::SimpleRequest<swift::TypeCheckFunctionBodyUntilRequest, bool (swift::AbstractFunctionDecl*, swift::SourceLoc), (swift::CacheKind)1>::evaluateRequest(swift::TypeCheckFunctionBodyUntilRequest const&, swift::Evaluator&) + 2879
14 swift                    0x0000000104284b6e swift::TypeCheckFunctionBodyUntilRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyUntilRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyUntilRequest, swift::TypeCheckFunctionBodyUntilRequest::OutputType) + 718
15 swift                    0x00000001042b36ce swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*, unsigned int) const + 6270
16 swift                    0x0000000104282b47 swift::SimpleRequest<swift::TypeCheckSourceFileRequest, bool (swift::SourceFile*, unsigned int), (swift::CacheKind)2>::evaluateRequest(swift::TypeCheckSourceFileRequest const&, swift::Evaluator&) + 23
17 swift                    0x00000001042b0fce swift::performTypeChecking(swift::SourceFile&, unsigned int) + 1006
18 swift                    0x00000001038e505b swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 5915
19 swift                    0x00000001035d12c9 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 10281
20 swift                    0x00000001035524d3 main + 1283
21 libdyld.dylib            0x00007fff6c6adcc9 start + 1
@LucianoPAlmeida
Copy link
Collaborator Author

Not sure if it's the same problem of SR-12425, but the crash is in the same place apparently
cc @xedin @hamishknight

@LucianoPAlmeida
Copy link
Collaborator Author

Here's a PR #31140

@xedin
Copy link
Member

xedin commented Apr 20, 2020

@LucianoPAlmeida Seems like the same problem, I'd suggest you test your fix against the example in SR-12425 and dupe this one to it.

@LucianoPAlmeida
Copy link
Collaborator Author

@xedin I've added the test case, the crash is fixed, but the diagnostics for SR-12425 are not good so what do you think about letting it opened until the diagnostics improve?
I'll try to send a follow up to that 🙂

@xedin
Copy link
Member

xedin commented Apr 21, 2020

Sure, we can keep the other SR open until diagnostics are fixed.

@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

3 participants