Skip to content

[SR-9239] Crash with default argument in initializer for @dynamicCallable struct #51727

@harlanhaskins

Description

@harlanhaskins
Previous ID SR-9239
Radar None
Original Reporter @harlanhaskins
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @Azoy
Priority Medium

md5: 1af6665a70d50a07649e5533d9613bc5

Issue Description:

@dynamicCallable struct A { init(_ x: Int = 0) {} func dynamicallyCall(withArguments args: [Int]) {} } A()()

The above code trips this assertion while constraint solving:

/tmp/init.swift:7:1: error: type of expression is ambiguous without more context A()() ^~~ Assertion failed: (hasType(E) && "Expected type to have been set!"), function getType, file /Users/harlan/Swift/swift/lib/Sema/ConstraintSystem.h, line 1683. Stack dump: 0. Program arguments: /Users/harlan/Swift/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -frontend -emit-sil -primary-file /tmp/init.swift -target x86_64-apple-darwin18.2.0 -enable-objc-interop -color-diagnostics -module-name init -o - 1. While type-checking statement at [/tmp/init.swift:7:1 - line:7:5] RangeText="A()(" 2. While type-checking expression at [/tmp/init.swift:7:1 - line:7:5] RangeText="A()(" 0 swift 0x00000001043dd425 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37 1 swift 0x00000001043dc408 llvm::sys::RunSignalHandlers() + 248 2 swift 0x00000001043dda32 SignalHandler(int) + 258 3 libsystem_platform.dylib 0x00007fff681c7b3d _sigtramp + 29 4 swift 0x00000001056d8be5 cmark_strbuf__initbuf + 133936 5 libsystem_c.dylib 0x00007fff680851c9 abort + 127 6 libsystem_c.dylib 0x00007fff6804d868 basename_r + 0 7 swift 0x000000010154af94 swift::constraints::ConstraintSystem::getType(swift::Expr const*) const + 356 8 swift 0x0000000101423937 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 55 9 swift 0x0000000101850a16 swift::Expr::walk(swift::ASTWalker&) + 118 10 swift 0x000000010141b3ae swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool) + 510 11 swift 0x000000010154abb0 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1136 12 swift 0x00000001015dee08 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 600 13 swift 0x00000001015ddfc8 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136 14 swift 0x00000001015de0de swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 174 15 swift 0x00000001015feb8e swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 846 16 swift 0x0000000100dc8c3c swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 492 17 swift 0x0000000100dc75c3 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 435 18 swift 0x0000000100dc6c87 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 615 19 swift 0x000000010051fd88 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1192 20 swift 0x000000010051e878 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3016 21 swift 0x00000001004d0962 main + 690 22 libdyld.dylib 0x00007fff67fdcef9 start + 1

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of software

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions