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-11600] Property Wrapper composition crash with optional type #54005

Closed
theblixguy opened this issue Oct 10, 2019 · 4 comments
Closed

[SR-11600] Property Wrapper composition crash with optional type #54005

theblixguy opened this issue Oct 10, 2019 · 4 comments
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 property wrappers Feature: property wrappers type checker Area → compiler: Semantic analysis

Comments

@theblixguy
Copy link
Collaborator

Previous ID SR-11600
Radar rdar://problem/56190606
Original Reporter @theblixguy
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 5.1.1-dev (LLVM 1f54080bb6, Swift 97339a6)
Target: x86_64-apple-darwin19.0.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, PropertyWrappers, TypeChecker
Assignee None
Priority Medium

md5: dbdba94e8c3d71c887ff6f8245e99b16

relates to:

  • SR-11599 Property Wrapper composition crash

Issue Description:

@propertyWrapper struct A {
  var wrappedValue: Int
}

@propertyWrapper struct B {
  var wrappedValue: Int
}

struct C {
  @A @B var foo: Int?
}
Stack dump:
0.  Program arguments: ./swiftc -frontend -typecheck /Users/suyashsrijan/Desktop/test.swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
1.  Swift version 5.1.1-dev (LLVM 1f54080bb6, Swift 97339a6ace)
2.  While evaluating request TypeCheckFunctionBodyUntilRequest(test.(file).C._@/Users/suyashsrijan/Desktop/test.swift:10:13, )
3.  While type-checking setter for foo (at /Users/suyashsrijan/Desktop/test.swift:10:13)
4.  While evaluating request ParseAbstractFunctionBodyRequest(test.(file).C._@/Users/suyashsrijan/Desktop/test.swift:10:13)
0  swiftc                   0x000000010f63daf5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swiftc                   0x000000010f63cda5 llvm::sys::RunSignalHandlers() + 85
2  swiftc                   0x000000010f63e0d8 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff69a23b1d _sigtramp + 29
4  libsystem_platform.dylib 0x000000011b06ffff _sigtramp + 2976171263
5  swiftc                   0x000000010c4f80da createPropertyStoreOrCallSuperclassSetter(swift::AccessorDecl*, swift::Expr*, swift::AbstractStorageDecl*, (anonymous namespace)::TargetImpl, llvm::SmallVectorImpl<swift::ASTNode>&, swift::ASTContext&) + 1802
6  swiftc                   0x000000010c4f97b9 synthesizeTrivialSetterBodyWithStorage(swift::AccessorDecl*, (anonymous namespace)::TargetImpl, swift::AbstractStorageDecl*, swift::ASTContext&) + 201
7  swiftc                   0x000000010c4f76ce synthesizeAccessorBody(swift::AbstractFunctionDecl*, void*) + 3198
8  swiftc                   0x000000010c72964f swift::ParseAbstractFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 79
9  swiftc                   0x000000010c7297f1 swift::SimpleRequest<swift::ParseAbstractFunctionBodyRequest, swift::BraceStmt* (swift::AbstractFunctionDecl*), (swift::CacheKind)2>::evaluateRequest(swift::ParseAbstractFunctionBodyRequest const&, swift::Evaluator&) + 17
10 swiftc                   0x000000010c87e810 llvm::Expected<swift::ParseAbstractFunctionBodyRequest::OutputType> swift::Evaluator::getResultUncached<swift::ParseAbstractFunctionBodyRequest>(swift::ParseAbstractFunctionBodyRequest const&) + 384
11 swiftc                   0x000000010c87e572 llvm::Expected<swift::ParseAbstractFunctionBodyRequest::OutputType> swift::Evaluator::getResultCached<swift::ParseAbstractFunctionBodyRequest, (void*)0>(swift::ParseAbstractFunctionBodyRequest const&) + 66
12 swiftc                   0x000000010c87d8fb llvm::Expected<swift::ParseAbstractFunctionBodyRequest::OutputType> swift::Evaluator::operator()<swift::ParseAbstractFunctionBodyRequest>(swift::ParseAbstractFunctionBodyRequest const&) + 107
13 swiftc                   0x000000010c83df43 swift::ParseAbstractFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::ParseAbstractFunctionBodyRequest>(swift::Evaluator&, swift::ParseAbstractFunctionBodyRequest, swift::ParseAbstractFunctionBodyRequest::OutputType) + 35
14 swiftc                   0x000000010c4e8b07 swift::TypeCheckFunctionBodyUntilRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*, swift::SourceLoc) const + 359
15 swiftc                   0x000000010c4e6635 swift::SimpleRequest<swift::TypeCheckFunctionBodyUntilRequest, bool (swift::AbstractFunctionDecl*, swift::SourceLoc), (swift::CacheKind)1>::evaluateRequest(swift::TypeCheckFunctionBodyUntilRequest const&, swift::Evaluator&) + 21
16 swiftc                   0x000000010c4f1097 llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyUntilRequest>(swift::TypeCheckFunctionBodyUntilRequest const&) + 391
17 swiftc                   0x000000010c4f0bd0 llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckFunctionBodyUntilRequest, (void*)0>(swift::TypeCheckFunctionBodyUntilRequest const&) + 240
18 swiftc                   0x000000010c4efdab llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::operator()<swift::TypeCheckFunctionBodyUntilRequest>(swift::TypeCheckFunctionBodyUntilRequest const&) + 107
19 swiftc                   0x000000010c4e9666 swift::TypeCheckFunctionBodyUntilRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyUntilRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyUntilRequest, swift::TypeCheckFunctionBodyUntilRequest::OutputType) + 38
20 swiftc                   0x000000010c4e8964 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 36
21 swiftc                   0x000000010c515ec8 typeCheckFunctionsAndExternalDecls(swift::SourceFile&, swift::TypeChecker&) + 312
22 swiftc                   0x000000010c5168df swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 1775
23 swiftc                   0x000000010bc6c459 swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 489
24 swiftc                   0x000000010bc6b0e7 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 519
25 swiftc                   0x000000010bc6a8ed swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 621
26 swiftc                   0x000000010ba534c2 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1650
27 swiftc                   0x000000010ba51ee6 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3046
28 swiftc                   0x000000010b9fbb59 main + 729
29 libdyld.dylib            0x00007fff69822405 start + 1
zsh: segmentation fault  ./swiftc -frontend -typecheck ~/Desktop/test.swift
@belkadan
Copy link
Contributor

Hm. This is the "property wrapper can override the type of the property" bug again, but I'm not sure why it's interacting extra badly with the double wrapping, which I thought was still not allowed on 5.1.

@swift-ci create

@theblixguy
Copy link
Collaborator Author

Property wrapper composition is not allowed on 5.1, but it is allowed on master (which is what I am on). The compiler does produce diagnostics, but still crashes:

/Users/suyashsrijan/Desktop/test.swift:10:13: error: property type 'Int?' does not match that of the 'wrappedValue' property of its wrapper type 'A'
  @A @B var foo: Int?
            ^
/Users/suyashsrijan/Desktop/test.swift:1:25: note: property wrapper type 'A' declared here
@propertyWrapper struct A {
                        ^
<unknown>:0: error: 'nil' is not compatible with expected argument type 'Int'
/Users/suyashsrijan/Desktop/test.swift:10:7: error: cannot convert value of type 'B' to expected argument type 'Int'
  @A @B var foo: Int?
      ^

@theblixguy
Copy link
Collaborator Author

Interesting, it reproduces even without composition. This causes the same crash

@propertyWrapper 
struct A {
  var wrappedValue: Int
}

struct B {
  @A var foo: Int?
}

It also produces incorrect diagnostics (alongside correct diagnostics):

/Users/suyashsrijan/Desktop/test.swift:7:10: error: value of optional type 'Int?' must be unwrapped to a value of type 'Int'
  @A var foo: Int?
         ^
/Users/suyashsrijan/Desktop/test.swift:7:10: note: coalesce using '??' to provide a default when the optional value contains 'nil'
  @A var foo: Int?
         ^
             ?? <#default value#>
/Users/suyashsrijan/Desktop/test.swift:7:10: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
  @A var foo: Int?
         ^
         (  )!

This seems like a regression... I wonder if the recent requestification of some things have something to do with this.

@theblixguy
Copy link
Collaborator Author

Fixed by #27995

@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 property wrappers Feature: property wrappers type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants