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-11684] Property wrapper crash when property is optional and wrappedValue is non-optional #54093

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

Comments

@theblixguy
Copy link
Collaborator

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

Swift version 5.1.1-dev (Swift dfd805f)
Target: x86_64-apple-darwin19.0.0

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

md5: 15265c04cd92b2cd8374532b30c07d29

Issue Description:

This code crashes after emitting diagnostics:

@propertyWrapper 
struct Wrapper {
  var wrappedValue: Int
}

class Test {
  @Wrapper var user: Int?
}

with the following stack trace:

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 (Swift dfd805f53e)
2.  While evaluating request TypeCheckFunctionBodyUntilRequest(test.(file).Test._@/Users/suyashsrijan/Desktop/test.swift:7:16, )
3.  While type-checking setter for user (at /Users/suyashsrijan/Desktop/test.swift:7:16)
4.  While evaluating request ParseAbstractFunctionBodyRequest(test.(file).Test._@/Users/suyashsrijan/Desktop/test.swift:7:16)
0  swiftc                   0x000000010bd24b55 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swiftc                   0x000000010bd23e05 llvm::sys::RunSignalHandlers() + 85
2  swiftc                   0x000000010bd25138 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff69a23b1d _sigtramp + 29
4  libsystem_platform.dylib 0x000000000000ffff _sigtramp + 2522793215
5  swiftc                   0x0000000108c15b3a createPropertyStoreOrCallSuperclassSetter(swift::AccessorDecl*, swift::Expr*, swift::AbstractStorageDecl*, (anonymous namespace)::TargetImpl, llvm::SmallVectorImpl<swift::ASTNode>&, swift::ASTContext&) + 1802
6  swiftc                   0x0000000108c1724e synthesizeTrivialSetterBodyWithStorage(swift::AccessorDecl*, (anonymous namespace)::TargetImpl, swift::AbstractStorageDecl*, swift::ASTContext&) + 206
7  swiftc                   0x0000000108c1511e synthesizeAccessorBody(swift::AbstractFunctionDecl*, void*) + 3214
8  swiftc                   0x0000000108e12310 swift::ParseAbstractFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 80
9  swiftc                   0x0000000108e124b1 swift::SimpleRequest<swift::ParseAbstractFunctionBodyRequest, swift::BraceStmt* (swift::AbstractFunctionDecl*), (swift::CacheKind)2>::evaluateRequest(swift::ParseAbstractFunctionBodyRequest const&, swift::Evaluator&) + 17
10 swiftc                   0x0000000108f643a0 llvm::Expected<swift::ParseAbstractFunctionBodyRequest::OutputType> swift::Evaluator::getResultUncached<swift::ParseAbstractFunctionBodyRequest>(swift::ParseAbstractFunctionBodyRequest const&) + 384
11 swiftc                   0x0000000108f64100 llvm::Expected<swift::ParseAbstractFunctionBodyRequest::OutputType> swift::Evaluator::getResultCached<swift::ParseAbstractFunctionBodyRequest, (void*)0>(swift::ParseAbstractFunctionBodyRequest const&) + 64
12 swiftc                   0x0000000108f6346b llvm::Expected<swift::ParseAbstractFunctionBodyRequest::OutputType> swift::Evaluator::operator()<swift::ParseAbstractFunctionBodyRequest>(swift::ParseAbstractFunctionBodyRequest const&) + 107
13 swiftc                   0x0000000108f18863 swift::ParseAbstractFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::ParseAbstractFunctionBodyRequest>(swift::Evaluator&, swift::ParseAbstractFunctionBodyRequest, swift::ParseAbstractFunctionBodyRequest::OutputType) + 35
14 swiftc                   0x0000000108c06547 swift::TypeCheckFunctionBodyUntilRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*, swift::SourceLoc) const + 359
15 swiftc                   0x0000000108c03f45 swift::SimpleRequest<swift::TypeCheckFunctionBodyUntilRequest, bool (swift::AbstractFunctionDecl*, swift::SourceLoc), (swift::CacheKind)1>::evaluateRequest(swift::TypeCheckFunctionBodyUntilRequest const&, swift::Evaluator&) + 21
16 swiftc                   0x0000000108c0ebe7 llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyUntilRequest>(swift::TypeCheckFunctionBodyUntilRequest const&) + 391
17 swiftc                   0x0000000108c0e720 llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckFunctionBodyUntilRequest, (void*)0>(swift::TypeCheckFunctionBodyUntilRequest const&) + 240
18 swiftc                   0x0000000108c0d8fb llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::operator()<swift::TypeCheckFunctionBodyUntilRequest>(swift::TypeCheckFunctionBodyUntilRequest const&) + 107
19 swiftc                   0x0000000108c07096 swift::TypeCheckFunctionBodyUntilRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyUntilRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyUntilRequest, swift::TypeCheckFunctionBodyUntilRequest::OutputType) + 38
20 swiftc                   0x0000000108c0639e swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 30
21 swiftc                   0x0000000108c33868 typeCheckFunctionsAndExternalDecls(swift::SourceFile&, swift::TypeChecker&) + 312
22 swiftc                   0x0000000108c34293 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 1795
23 swiftc                   0x0000000108377369 swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 489
24 swiftc                   0x0000000108375fa7 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 519
25 swiftc                   0x00000001083757ad swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 621
26 swiftc                   0x000000010815d731 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1681
27 swiftc                   0x000000010815c126 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3046
28 swiftc                   0x0000000108105d99 main + 729
29 libdyld.dylib            0x00007fff69822405 start + 1

Also, some of the diagnostics are completely wrong, but that's a separate issue.

@theblixguy
Copy link
Collaborator Author

The problem here is that the synthesised setter for user is trying to assign a value of type Int? into a storage of type Int, hence the crash (doing getOptionalObjectType() on it will just return a null type). I think we should check that it's not a null type and bail out if it is.

@zoecarver
Copy link
Collaborator

Mind if I take this one?

@belkadan
Copy link
Contributor

[Cloning into Radar so Apple folks can track the fix into a release, even if you end up being the one to fix it, Zoe.]

@swift-ci create

@theblixguy
Copy link
Collaborator Author

I already have a fix for it (did it differently than suggested above, which takes care of bogus diagnostics as well). I'll create a PR shortly

@theblixguy
Copy link
Collaborator Author

#27995

@zoecarver
Copy link
Collaborator

Sounds good.

@theblixguy
Copy link
Collaborator Author

Fixed on master.

@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

4 participants