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-11085] Sema crash: These contextual type purposes cannot fail with a conversion type specified #53477

Closed
rxwei opened this issue Jul 8, 2019 · 10 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 type checker Area → compiler: Semantic analysis

Comments

@rxwei
Copy link
Member

rxwei commented Jul 8, 2019

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()
@rxwei
Copy link
Member Author

rxwei commented Jul 8, 2019

@xedin

@theblixguy
Copy link
Collaborator

PR: #26074

@theblixguy
Copy link
Collaborator

Fixed on master

@theblixguy
Copy link
Collaborator

Reopening this ticket because the fix was reverted due to causing a regression with generics type resolution (SR-11223).

@hamishknight
Copy link
Collaborator

@theblixguy Are you still working on this? If not, I'd like to try and have a crack at it using the request evaluator.

@theblixguy
Copy link
Collaborator

@hamishknight I am not, feel free to assign it to yourself!

@hamishknight
Copy link
Collaborator

Thanks!

@davezarzycki
Copy link
Collaborator

#28106

@hamishknight
Copy link
Collaborator

#28279

@hamishknight
Copy link
Collaborator

Fixed by #28279 @rxwei please verify using the next available master snapshot from https://swift.org/download/#snapshots.

@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

5 participants