Skip to content

Property Wrapper make compiler crash in function body (Xcode 14 and main?) #59294

@freddi-kit

Description

@freddi-kit

Describe the bug

Property Wrapper make compiler crash in function body. It can be reproduced with below code.

import Foundation

@propertyWrapper
struct WrapperValue<Value> {
  var value: Value
  init(wrappedValue: Value) {
    self.value = wrappedValue
  }

  var projectedValue: Self {
    return self
  }
  
  var wrappedValue: Value {
    get {
      self.value  
    }
    set {
      self.value = newValue
    }
  }

  func printValue() {
    print(value)
  }
}


class Test {
  static func test() {
    return [0, 1, 2].compactMap { _ in
      @WrapperValue var value: Bool? = false
      if value != nil {
        return false
      }

      return value ?? false
    }
  }
}

I have already reported as feedback to apple (FB10059129)

To Reproduce
Compile first attached code.

Expected behavior
Crash with below log.

Screenshots

error: compile command failed due to signal 4 (use -v to see invocation)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.	Program arguments: "/Applications/Xcode-14 beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend" -frontend -c -primary-file testtest.swift -target x86_64-apple-macosx12.0 -enable-objc-interop -stack-check -sdk "/Applications/Xcode-14 beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk" -color-diagnostics -new-driver-path "/Applications/Xcode-14 beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver" -empty-abi-descriptor -resource-dir "/Applications/Xcode-14 beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift" -module-name testtest -disable-clang-spi -target-sdk-version 13.0 -o /var/folders/6l/g6r_nm2d07b0hcjtqn1gv84c0000gq/T/TemporaryDirectory.NuIWv3/testtest-1.o
1.	Apple Swift version 5.7 (swiftlang-5.7.0.113.202 clang-1400.0.16.2)
2.	Compiling with the current language version
3.	While evaluating request TypeCheckSourceFileRequest(source_file "testtest.swift")
4.	While evaluating request TypeCheckFunctionBodyRequest(testtest.(file).Test.test()@testtest.swift:30:15)
5.	While type-checking statement at [testtest.swift:30:22 - line:39:3] RangeText="{
    return [0, 1, 2].compactMap { _ in
      @WrapperValue var value: Bool? = false
      if value != nil {
        return false
      }

      return value ?? false
    }
  "
6.	While type-checking statement at [testtest.swift:31:5 - line:38:5] RangeText="return [0, 1, 2].compactMap { _ in
      @WrapperValue var value: Bool? = false
      if value != nil {
        return false
      }

      return value ?? false
    "
7.	While type-checking expression at [testtest.swift:31:12 - line:38:5] RangeText="[0, 1, 2].compactMap { _ in
      @WrapperValue var value: Bool? = false
      if value != nil {
        return false
      }

      return value ?? false
    "
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-frontend           0x000000011550c107 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x000000011550b158 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x000000011550c720 SignalHandler(int) + 288
3  libsystem_platform.dylib 0x00007ff80aaacdfd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603370401968672
5  swift-frontend           0x0000000110dc2ffd (anonymous namespace)::ConstraintWalker::walkToExprPost(swift::Expr*) + 989
6  swift-frontend           0x000000011143d596 (anonymous namespace)::Traversal::doIt(swift::ArgumentList*) + 166
7  swift-frontend           0x000000011143d759 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 361
8  swift-frontend           0x000000011143d57b (anonymous namespace)::Traversal::doIt(swift::ArgumentList*) + 139
9  swift-frontend           0x000000011143d759 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 361
10 swift-frontend           0x0000000110dbdc6a swift::constraints::ConstraintSystem::generateConstraints(swift::Expr*, swift::DeclContext*, bool) + 234
11 swift-frontend           0x0000000110dbc4db swift::constraints::ConstraintSystem::generateConstraints(swift::constraints::SolutionApplicationTarget&, swift::FreeTypeVariableBinding) + 459
12 swift-frontend           0x0000000110dbb3f6 (anonymous namespace)::ClosureConstraintGenerator::visitDecl(swift::Decl*) + 854
13 swift-frontend           0x0000000110db4ff5 swift::constraints::ConstraintSystem::simplifyClosureBodyElementConstraint(swift::ASTNode, swift::constraints::ContextualTypeInfo, bool, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 933
14 swift-frontend           0x0000000110e2176b swift::constraints::ConstraintSystem::simplifyConstraint(swift::constraints::Constraint const&) + 3643
15 swift-frontend           0x0000000110e396d1 swift::constraints::ConjunctionElement::attempt(swift::constraints::ConstraintSystem&) const + 241
16 swift-frontend           0x0000000110e45f4b swift::constraints::ConjunctionStep::attempt(swift::constraints::ConjunctionElement const&) + 315
17 swift-frontend           0x0000000110e472de swift::constraints::BindingStep<swift::constraints::ConjunctionElementProducer>::take(bool) + 494
18 swift-frontend           0x0000000110e31f5d swift::constraints::ConstraintSystem::solveImpl(llvm::SmallVectorImpl<swift::constraints::Solution>&) + 541
19 swift-frontend           0x0000000110ede2da swift::constraints::ConstraintSystem::salvage() + 170
20 swift-frontend           0x0000000110e3487d swift::constraints::ConstraintSystem::solve(swift::constraints::SolutionApplicationTarget&, swift::FreeTypeVariableBinding) + 1885
21 swift-frontend           0x000000011100094e swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 798
22 swift-frontend           0x00000001110ef401 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 6545
23 swift-frontend           0x00000001110ed9e8 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::Stmt>(swift::Stmt*&) + 296
24 swift-frontend           0x00000001110ea36b (anonymous namespace)::StmtChecker::typeCheckASTNode(swift::ASTNode&) + 171
25 swift-frontend           0x00000001110edaec swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 124
26 swift-frontend           0x00000001110ec698 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 296
27 swift-frontend           0x00000001110eb1be swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 1806
28 swift-frontend           0x000000011151b87d llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest>(swift::TypeCheckFunctionBodyRequest const&) + 669
29 swift-frontend           0x00000001114a9a3e swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType) + 94
30 swift-frontend           0x000000011112e8fb swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 875
31 swift-frontend           0x000000011113198d llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 669
32 swift-frontend           0x000000011112e542 swift::performTypeChecking(swift::SourceFile&) + 114
33 swift-frontend           0x00000001101722b9 swift::CompilerInstance::performSema() + 217
34 swift-frontend           0x00000001100f653c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5164
35 swift-frontend           0x00000001100903aa swift::mainEntry(int, char const**) + 3082
36 dyld                     0x0000000125baa51e start + 462

Environment (please complete the following information):

  • Xcode 14 beta 14A5228q
  • nightly build (Swift version 5.8-dev (LLVM 278d67f38c6a910, Swift ee312bc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions