Closed
Description
Previous ID | SR-11085 |
Radar | rdar://problem/56144412 |
Original Reporter | @rxwei |
Type | Bug |
Status | Resolved |
Resolution | Done |
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, CompilerCrash, TypeChecker |
Assignee | @hamishknight |
Priority | Medium |
md5: b71a9600d6cf35f0af6bc90c1b69bdd5
Issue Description:
Sema crashes on the following code. While #line
definitely does not have type String
, the compiler should not crash.
func foo(x: Int) {}
func foo(line: String = #line) {}
foo()
➜ Desktop swiftc defaultargs.swift
These contextual type purposes cannot fail with a conversion type specified!
UNREACHABLE executed at /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/Sema/CSDiag.cpp:2068!
Stack dump:
0. Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-07-03-a.xctoolchain/usr/bin/swift -frontend -c -primary-file defaultargs.swift -target x86_64-apple-darwin18.6.0 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name defaultargs -o /var/folders/b1/qdyl0rys4q7d4fcxbjn78rhc00h255/T/defaultargs-2bdfb6.o
1. Apple Swift version 5.1-dev (LLVM 8d110eebee, Swift 8221c6735c)
2. While type-checking statement at [defaultargs.swift:3:1 - line:3:5] RangeText="foo("
3. While type-checking expression at [defaultargs.swift:3:1 - line:3:5] RangeText="foo("
4. While type-checking expression at [defaultargs.swift:3:4 - line:3:4] RangeText=""
0 swift 0x000000010d34bc95 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1 swift 0x000000010d34af85 llvm::sys::RunSignalHandlers() + 85
2 swift 0x000000010d34c278 SignalHandler(int) + 264
3 libsystem_platform.dylib 0x00007fff63a92b5d _sigtramp + 29
4 libsystem_platform.dylib 0x0000000000000052 _sigtramp + 2622936338
5 libsystem_c.dylib 0x00007fff6394c6a6 abort + 127
6 swift 0x000000010e45b21e llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 462
7 swift 0x000000010a383cd6 (anonymous namespace)::FailureDiagnosis::diagnoseContextualConversionError(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::Type) + 8790
8 swift 0x000000010a38004a swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 122
9 swift 0x000000010a430a67 swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 1303
10 swift 0x000000010a3daf3c swift::constraints::ConstraintSystem::solve(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 508
11 swift 0x000000010a494ca4 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 964
12 swift 0x000000010a495159 swift::TypeChecker::typeCheckParameterDefault(swift::Expr*&, swift::DeclContext*, swift::Type, bool, bool) + 281
13 swift 0x000000010a374971 getCallerDefaultArg(swift::constraints::ConstraintSystem&, swift::DeclContext*, swift::SourceLoc, swift::ConcreteDeclRef&, unsigned int) + 849
14 swift 0x000000010a3734b7 (anonymous namespace)::ExprRewriter::coerceCallArguments(swift::Expr*, swift::AnyFunctionType*, swift::ApplyExpr*, llvm::ArrayRef<swift::Identifier>, bool, swift::constraints::ConstraintLocatorBuilder) + 2279
15 swift 0x000000010a363188 (anonymous namespace)::ExprRewriter::finishApply(swift::ApplyExpr*, swift::Type, swift::constraints::ConstraintLocatorBuilder) + 3832
16 swift 0x000000010a375bdb (anonymous namespace)::ExprRewriter::visitApplyExpr(swift::ApplyExpr*) + 123
17 swift 0x000000010a365876 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 22
18 swift 0x000000010a7788d3 swift::Expr::walk(swift::ASTWalker&) + 115
19 swift 0x000000010a35c96c swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool) + 492
20 swift 0x000000010a494d33 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 1107
21 swift 0x000000010a4948cf swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 63
22 swift 0x000000010a52d5aa swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 602
23 swift 0x000000010a52c6d8 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136
24 swift 0x000000010a52c7ce swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 174
25 swift 0x000000010a54cbb2 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 914
26 swift 0x0000000109d078d6 swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 502
27 swift 0x0000000109d066e6 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 342
28 swift 0x0000000109d0608a swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 618
29 swift 0x0000000109afaae2 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1730
30 swift 0x0000000109af94e2 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3026
31 swift 0x0000000109aa1659 main + 729
32 libdyld.dylib 0x00007fff638a73d5 start + 1
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)
However, this works fine.
func foo() {}
func foo(line: String = #line) {}
foo()