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-10598] Assertion failure in buildKeyPathPropertyComponent() attempting to call a method #52998

Closed
benlangmuir opened this issue May 1, 2019 · 2 comments
Assignees
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 key paths Feature: key paths (both native and Objective-C) type checker Area → compiler: Semantic analysis

Comments

@benlangmuir
Copy link
Member

Previous ID SR-10598
Radar rdar://problem/50376224
Original Reporter @benlangmuir
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, KeyPaths, TypeChecker
Assignee @xedin
Priority Medium

md5: b182094cfc0d2ab6ab4274d161864e8e

Issue Description:

Type checker asserts if you try to call a method via keypath dynamic member lookup. It's invalid, but shouldn't crash.

$ cat t.swift 
struct S {
  var foo: Int
  func bar() -> Int { return 0}
}

@dynamicMemberLookup
struct A<T> {
  var obj: T
  init(_ obj: T) { self.obj = obj }
  subscript<U>(dynamicMember member: KeyPath<T, U>) -> U {
    return obj[keyPath: member]
  }
}

func test(x: A<S>) {
  _ = x.foo // OK
  _ = x.bar() // CRASH
}

$ swiftc -typecheck t.swift
Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /Users/blangmuir/src/s/llvm/include/llvm/Support/Casting.h, line 255.
Stack dump:
0.  Program arguments: /Users/blangmuir/src/s/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swift -frontend -typecheck -primary-file t.swift -target x86_64-apple-darwin19.0.0 -enable-objc-interop -color-diagnostics -module-name t 
1.  Swift version 5.0-dev (LLVM 082dec2e22, Swift 24139eae61)
2.  While type-checking 'test(x:)' (at t.swift:15:1)
3.  While type-checking statement at [t.swift:15:20 - line:18:1] RangeText="{
  _ = x.foo // OK
  _ = x.bar() // CRASH
"
4.  While type-checking expression at [t.swift:17:3 - line:17:13] RangeText="_ = x.bar("
0  swift                    0x00000001055671e5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x00000001055664a5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x00000001055677c8 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff632cf8bd _sigtramp + 29
4  libsystem_platform.dylib 0x0000000110a7ec08 _sigtramp + 2910516072
5  libsystem_c.dylib        0x00007fff6318b8b6 abort + 127
6  libsystem_c.dylib        0x00007fff631544e9 basename_r + 0
7  swift                    0x00000001023ba3c1 (anonymous namespace)::ExprRewriter::buildKeyPathPropertyComponent(swift::constraints::SelectedOverload const&, swift::SourceLoc, swift::constraints::ConstraintLocator*) + 529
8  swift                    0x00000001023b9388 (anonymous namespace)::ExprRewriter::buildKeyPathDynamicMemberIndexExpr(swift::BoundGenericType*, swift::SourceLoc, swift::constraints::ConstraintLocator*) + 1368
9  swift                    0x00000001023b72c9 (anonymous namespace)::ExprRewriter::buildDynamicMemberLookupRef(swift::Expr*, swift::Expr*, swift::SourceLoc, swift::SourceLoc, swift::constraints::SelectedOverload const&, swift::constraints::ConstraintLocator*) + 265
10 swift                    0x00000001023af37e swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) + 10366
11 swift                    0x00000001023ac91d (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 29
12 swift                    0x000000010280de4b (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 123
13 swift                    0x000000010280bfc7 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 2871
14 swift                    0x000000010280ae64 swift::Expr::walk(swift::ASTWalker&) + 84
15 swift                    0x00000001023a45e6 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool) + 534
16 swift                    0x00000001024e973a swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 1066
17 swift                    0x00000001024e92ff swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 63
18 swift                    0x0000000102589f06 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 614
19 swift                    0x0000000102588e88 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136
20 swift                    0x0000000102587911 swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, swift::SourceLoc) + 401
21 swift                    0x000000010258853f swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 271
22 swift                    0x00000001025a9ef2 typeCheckFunctionsAndExternalDecls(swift::SourceFile&, swift::TypeChecker&) + 322
23 swift                    0x00000001025aaa9b swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 1019
24 swift                    0x0000000101d07e26 swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 502
25 swift                    0x0000000101d06ab3 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 339
26 swift                    0x0000000101d062a7 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 615
27 swift                    0x0000000101ad0965 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1605
28 swift                    0x0000000101acf2c2 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2978
29 swift                    0x0000000101a76029 main + 729
30 libdyld.dylib            0x00007fff630de5dd start + 1
31 libdyld.dylib            0x000000000000000b start + 2633112111
[1]    85246 abort      bin/swiftc -typecheck t.swift
@benlangmuir
Copy link
Member Author

Does not crash if assertions are disabled.

@xedin
Copy link
Member

xedin commented May 3, 2019

Fixed by #24454

@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 key paths Feature: key paths (both native and Objective-C) type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants