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-11648] Cannot call member with default args through AnyObject lookup #54059

Closed
hamishknight opened this issue Oct 22, 2019 · 1 comment
Closed
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 type checker Area → compiler: Semantic analysis

Comments

@hamishknight
Copy link
Collaborator

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

Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)
Target: x86_64-apple-darwin18.7.0

Swift version 5.1.1-dev (Swift 022c6ac)
Target: x86_64-apple-darwin18.7.0

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

md5: 20a7f3bedac14f54d2b4e0ef3d24f29b

Issue Description:

In 5.1, the following fails to compile:

import Foundation

class C {
  @objc func foo(_ x: Int = 0) {}
}

func bar(_ x: AnyObject) {
  x.foo() // error: Cannot invoke 'foo' with no arguments
}

And on master it currently trips an assertion in CSApply:

Assertion failed: ((matchCanFail || !failed) && "Call arguments did not match up?"), function coerceCallArguments, file /Users/hamishknight/Desktop/swift-dev/swift/lib/Sema/CSApply.cpp, line 5438.
Stack dump:
0.  Program arguments: ./swift -frontend -typecheck /Users/hamishknight/Desktop/newnew/newnew/main.swift -debug-diagnostic-names -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/
1.  Swift version 5.1.1-dev (Swift 022c6accf2)
2.  While evaluating request TypeCheckFunctionBodyUntilRequest(main.(file).bar@/Users/hamishknight/Desktop/newnew/newnew/main.swift:443:6, )
3.  While type-checking 'bar(_:)' (at /Users/hamishknight/Desktop/newnew/newnew/main.swift:443:1)
4.  While type-checking statement at [/Users/hamishknight/Desktop/newnew/newnew/main.swift:443:26 - line:445:1] RangeText="{
  x.foo()
"
5.  While type-checking expression at [/Users/hamishknight/Desktop/newnew/newnew/main.swift:444:3 - line:444:9] RangeText="x.foo("
0  swift                    0x000000010b878a25 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000010b877a28 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x000000010b879018 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff65bc6b5d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000000004b38 _sigtramp + 2588139512
5  libsystem_c.dylib        0x00007fff65a806a6 abort + 127
6  libsystem_c.dylib        0x00007fff65a4920d basename_r + 0
7  swift                    0x000000010baf38b3 (anonymous namespace)::ExprRewriter::coerceCallArguments(swift::Expr*, swift::AnyFunctionType*, swift::ApplyExpr*, llvm::ArrayRef<swift::Identifier>, bool, swift::constraints::ConstraintLocatorBuilder) (.cold.53) + 35
8  swift                    0x0000000108231396 (anonymous namespace)::ExprRewriter::coerceCallArguments(swift::Expr*, swift::AnyFunctionType*, swift::ApplyExpr*, llvm::ArrayRef<swift::Identifier>, bool, swift::constraints::ConstraintLocatorBuilder) + 6630
9  swift                    0x000000010822e83b (anonymous namespace)::ExprRewriter::finishApply(swift::ApplyExpr*, swift::Type, swift::constraints::ConstraintLocatorBuilder) + 6651
10 swift                    0x000000010823529e (anonymous namespace)::ExprRewriter::visitApplyExpr(swift::ApplyExpr*) + 126
11 swift                    0x000000010821f3f6 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 22
12 swift                    0x00000001086dee33 swift::Expr::walk(swift::ASTWalker&) + 115
13 swift                    0x000000010821ac4c swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool) + 492
14 swift                    0x0000000108371667 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 1159
15 swift                    0x00000001083711cf swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 63
16 swift                    0x0000000108411b0b swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 603
17 swift                    0x0000000108410448 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136
18 swift                    0x000000010840f823 swift::TypeCheckFunctionBodyUntilRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*, swift::SourceLoc) const + 1283
19 swift                    0x000000010840cf45 swift::SimpleRequest<swift::TypeCheckFunctionBodyUntilRequest, bool (swift::AbstractFunctionDecl*, swift::SourceLoc), (swift::CacheKind)1>::evaluateRequest(swift::TypeCheckFunctionBodyUntilRequest const&, swift::Evaluator&) + 21
20 swift                    0x0000000108417b27 llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyUntilRequest>(swift::TypeCheckFunctionBodyUntilRequest const&) + 391
21 swift                    0x0000000108417660 llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckFunctionBodyUntilRequest, (void*)0>(swift::TypeCheckFunctionBodyUntilRequest const&) + 240
22 swift                    0x000000010841683b llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::operator()<swift::TypeCheckFunctionBodyUntilRequest>(swift::TypeCheckFunctionBodyUntilRequest const&) + 107
23 swift                    0x000000010840ffd6 swift::TypeCheckFunctionBodyUntilRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyUntilRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyUntilRequest, swift::TypeCheckFunctionBodyUntilRequest::OutputType) + 38
24 swift                    0x000000010840f2e4 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 36
25 swift                    0x000000010843c7a8 typeCheckFunctionsAndExternalDecls(swift::SourceFile&, swift::TypeChecker&) + 312
26 swift                    0x000000010843d1bf swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 1775
27 swift                    0x0000000107b8dfa9 swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 489
28 swift                    0x0000000107b8cbe7 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 519
29 swift                    0x0000000107b8c3ed swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 621
30 swift                    0x0000000107972f41 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1681
31 swift                    0x0000000107971946 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3046
32 swift                    0x0000000107916ee9 main + 729
33 libdyld.dylib            0x00007fff659db3d5 start + 1
fish: './swift -frontend -typecheck ~/…' terminated by signal SIGABRT (Abort)

But we should allow it to compile.

@hamishknight
Copy link
Collaborator Author

Fixed by #27836

@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

2 participants