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-14958] Compiler crash for class missing initializer #57300

Closed
rintaro mannequin opened this issue Jul 22, 2021 · 2 comments
Closed

[SR-14958] Compiler crash for class missing initializer #57300

rintaro mannequin opened this issue Jul 22, 2021 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@rintaro
Copy link
Mannequin

rintaro mannequin commented Jul 22, 2021

Previous ID SR-14958
Radar rdar://80755079
Original Reporter @rintaro
Type Bug
Status In Progress
Resolution
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee hanyakus (JIRA)
Priority Medium

md5: 8add0cc0301a103dd233c6f6c3f8ae80

Issue Description:

class Dat {
    let value1: Int
    let value2: Int
}
func test()  {
  (0..<1).map {
     Dat(value1: Int.random(0..<1), value2: $0)
  }

This crashes

test.swift:1:7: error: class 'Dat' has no initializers
class Dat {
      ^
test.swift:2:9: note: stored property 'value1' without initial value prevents synthesized initializers
    let value1: Int
        ^
                    = 0
test.swift:3:9: note: stored property 'value2' without initial value prevents synthesized initializers
    let value2: Int
        ^
                    = 0
Assertion failed: (hasType(node) && "Expected type to have been set!"), function getType, file ConstraintSystem.h, line 2977.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: ../build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -frontend -typecheck -sdk /Applications/Xcode/Sunriver/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk test.swift
1.  Swift version 5.5-dev (LLVM c5470fe8cba4606, Swift 382809ad084cb18)
2.  
3.  While evaluating request TypeCheckSourceFileRequest(source_file "test.swift")
4.  While evaluating request TypeCheckFunctionBodyRequest(test.(file).test()@test.swift:5:6)
5.  While type-checking statement at [test.swift:5:14 - line:9:1] RangeText="{
  (0..<1).map {
     Dat(value1: Int.random(0..<1), value2: $0)
  }
"
6.  While type-checking expression at [test.swift:6:3 - line:8:3] RangeText="(0..<1).map {
     Dat(value1: Int.random(0..<1), value2: $0)
  "
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift                    0x0000000106860fe7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift                    0x000000010685fef8 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x0000000106861846 SignalHandler(int) + 278
3  libsystem_platform.dylib 0x00007fff206e7d7d _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603339972051616
5  libsystem_c.dylib        0x00007fff205f7411 abort + 120
6  libsystem_c.dylib        0x00007fff205f67e8 err + 0
7  swift                    0x0000000106c12553 swift::constraints::ConstraintSystem::getType(swift::ASTNode) const (.cold.2) + 35
8  swift                    0x00000001028393d9 swift::constraints::ConstraintSystem::getType(swift::ASTNode) const + 201
9  swift                    0x000000010289a352 (anonymous namespace)::ConstraintOptimizer::walkToExprPre(swift::Expr*) + 322
10 swift                    0x0000000102ce4073 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 2963
11 swift                    0x0000000102ce2eb9 swift::Expr::walk(swift::ASTWalker&) + 73
12 swift                    0x000000010288c6c2 swift::constraints::ConstraintSystem::optimizeConstraints(swift::Expr*) + 2082
13 swift                    0x00000001028bec3d swift::constraints::ConstraintSystem::performMemberLookup(swift::constraints::ConstraintKind, swift::DeclNameRef, swift::Type, swift::FunctionRefKind, swift::constraints::ConstraintLocator*, bool) + 2701
14 swift                    0x0000000102910ec8 swift::constraints::MissingMemberFailure::diagnoseAsError() + 3624
15 swift                    0x00000001028f890b swift::constraints::DefineMemberBasedOnUse::diagnoseForAmbiguity(llvm::ArrayRef<std::__1::pair<swift::constraints::Solution const*, swift::constraints::ConstraintFix const*> >) const + 331
16 swift                    0x000000010295bf30 swift::constraints::ConstraintSystem::diagnoseAmbiguityWithFixes(llvm::SmallVectorImpl<swift::constraints::Solution>&) + 12576
17 swift                    0x0000000102958928 swift::constraints::ConstraintSystem::salvage() + 232
18 swift                    0x00000001028dcb61 swift::constraints::ConstraintSystem::solve(swift::constraints::SolutionApplicationTarget&, swift::FreeTypeVariableBinding) + 529
19 swift                    0x0000000102a09cb0 swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 480
20 swift                    0x0000000102a09a4e swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::constraints::ContextualTypeInfo, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 78
21 swift                    0x0000000102ac1cf5 (anonymous namespace)::StmtChecker::typeCheckASTNode(swift::ASTNode&) + 229
22 swift                    0x0000000102ac3cac swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 284
23 swift                    0x0000000102ac2f40 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 128
24 swift                    0x0000000102ac2474 swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 916
25 swift                    0x0000000102ddc4bf llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest>(swift::TypeCheckFunctionBodyRequest const&) + 415
26 swift                    0x0000000102ddc25b llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckFunctionBodyRequest, (void*)0>(swift::TypeCheckFunctionBodyRequest const&) + 107
27 swift                    0x0000000102d3c1e3 swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType) + 35
28 swift                    0x0000000102af5858 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 328
29 swift                    0x0000000102af6760 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 416
30 swift                    0x0000000102af6514 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 100
31 swift                    0x0000000102af561f swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 31
32 swift                    0x0000000101dedb6e swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<void (swift::SourceFile&)>) + 158
33 swift                    0x0000000101deda1a swift::CompilerInstance::performSema() + 74
34 swift                    0x0000000101cb7783 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5699
35 swift                    0x0000000101c61ac3 swift::mainEntry(int, char const**) + 499
36 libdyld.dylib            0x00007fff206bdf3d start + 1
37 libdyld.dylib            0x0000000000000006 start + 18446603339972223178

Since this is diagnosed error: 'Dat' cannot be constructed because it has no accessible initializers,

class Dat {
    let value1: Int
    let value2: Int
}
func test()  {
  Dat(value1: Int.random(0..<1), value2: 1) 
}

The Constraint System should diagnose it in the same way.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@xedin
Copy link
Member

xedin commented Jun 6, 2022

@rintaro Seems to work correctly on main, could you please verify and close?

@rintaro
Copy link
Member

rintaro commented Jun 30, 2022

Verified

@rintaro rintaro closed this as completed Jun 30, 2022
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
Projects
None yet
Development

No branches or pull requests

2 participants