Navigation Menu

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-11537] "TYPE MISMATCH IN ARGUMENT 0 OF APPLY AT expression" crash when using propertyWrapper #53938

Closed
JaviSoto opened this issue Sep 27, 2019 · 3 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

Comments

@JaviSoto
Copy link
Contributor

Previous ID SR-11537
Radar None
Original Reporter @JaviSoto
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 11 GM2 with its bundled Swift compiler, but also the snapshot from swift.org from 9/26

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

md5: c9c0873537f5ca3690a99b7ee9b00bee

Issue Description:

This was a tough one to reduce. I'm not exactly sure what it is, as some minor changes to my reduced example cause it to stop crashing. For example, putting the declaration of the var that has a property wrapper in the same file as the code that uses it makes it not crash. Also setting a value to that var in a different way also makes it not crash. I have attached an Xcode project that crashes with 9/26's Swift Snapshot as well. The code looks like this:

UserDefault.swift:

import Foundation


@propertyWrapper
public struct UserDefault<Value> {
    public let userDefaults: UserDefaults
    public let key: String
    private let defaultValue: Value
    
    public init(userDefaults: UserDefaults = .standard, key: String, defaultValue: Value) {
        self.userDefaults = userDefaults
        self.key = key
        self.defaultValue = defaultValue
    }
    
    public var wrappedValue: Value! {
        get {
            return userDefaults.object(forKey: key) as! Value? ?? defaultValue
        }
        set {
            userDefaults.setValue(newValue, forKey: key)
        }
    }
}

Setting.swift:

enum Settings {
    @UserDefault(key: "foo", defaultValue: true)
    static var mySetting: Bool
}

TableViewController.swift

import UIKit


class TableViewController: UITableViewController {
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        // This crashes the compiler:
        Settings.mySetting = indexPath.row.isMultiple(of: 2)
        
        // But replacing it with this doesn't:
        // Settings.mySetting = false
    }
}

The crash is:

TYPE MISMATCH IN ARGUMENT 0 OF APPLY AT expression at [/Users/jsbustos/Desktop/Playgrounds/PropertyWrapperCrash/PropertyWrapperCrash/Crashing Files/TableViewController.swift:14:9 - line:14:60] RangeText="Settings.mySetting = indexPath.row.isMultiple(of: 2"
  argument value:   %21 = apply %20<Int>(%18, %12) : $@convention(method) <τ_0_0 where τ_0_0 : FixedWidthInteger, τ_0_0 : SignedInteger> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0) -> Bool
  parameter type: $Optional<Bool>
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-09-26-a.xctoolchain/usr/bin/swift -frontend -c /Users/jsbustos/Desktop/Playgrounds/PropertyWrapperCrash/PropertyWrapperCrash/Crashing Files/Setting.swift /Users/jsbustos/Desktop/Playgrounds/PropertyWrapperCrash/PropertyWrapperCrash/AppDelegate.swift /Users/jsbustos/Desktop/Playgrounds/PropertyWrapperCrash/PropertyWrapperCrash/Crashing Files/UserDefault.swift /Users/jsbustos/Desktop/Playgrounds/PropertyWrapperCrash/PropertyWrapperCrash/SceneDelegate.swift -primary-file /Users/jsbustos/Desktop/Playgrounds/PropertyWrapperCrash/PropertyWrapperCrash/Crashing Files/TableViewController.swift /Users/jsbustos/Desktop/Playgrounds/PropertyWrapperCrash/PropertyWrapperCrash/ContentView.swift -emit-module-path /Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/Objects-normal/x86_64/TableViewController~partial.swiftmodule -emit-module-doc-path /Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/Objects-normal/x86_64/TableViewController~partial.swiftdoc -emit-module-source-info-path /Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/Objects-normal/x86_64/TableViewController~partial.swiftsourceinfo -serialize-diagnostics-path /Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/Objects-normal/x86_64/TableViewController.dia -emit-dependencies-path /Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/Objects-normal/x86_64/TableViewController.d -emit-reference-dependencies-path /Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/Objects-normal/x86_64/TableViewController.swiftdeps -target x86_64-apple-ios13.0-simulator -enable-objc-interop -sdk /Applications/Xcode11.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.0.sdk -I /Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Products/Debug-iphonesimulator -F /Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/jsbustos/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -enable-anonymous-context-mangled-names -Xcc -I/Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/PropertyWrapperCrash-generated-files.hmap -Xcc -I/Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/PropertyWrapperCrash-own-target-headers.hmap -Xcc -I/Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/PropertyWrapperCrash-all-target-headers.hmap -Xcc -iquote -Xcc /Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/PropertyWrapperCrash-project-headers.hmap -Xcc -I/Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/DerivedSources-normal/x86_64 -Xcc -I/Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/DerivedSources/x86_64 -Xcc -I/Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/jsbustos/Desktop/Playgrounds/PropertyWrapperCrash -module-name PropertyWrapperCrash -o /Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Build/Intermediates.noindex/PropertyWrapperCrash.build/Debug-iphonesimulator/PropertyWrapperCrash.build/Objects-normal/x86_64/TableViewController.o -index-store-path /Users/jsbustos/Library/Developer/Xcode/DerivedData/PropertyWrapperCrash-dydgnrxpgjjqsyfmfukjfdexzxku/Index/DataStore -index-system-modules 
1.  Apple Swift version 5.1-dev (LLVM c5340df2d1, Swift 8a91e98024)
2.  While emitting SIL for 'tableView(_:didSelectRowAt:)' (at /Users/jsbustos/Desktop/Playgrounds/PropertyWrapperCrash/PropertyWrapperCrash/Crashing Files/TableViewController.swift:12:14)
3.  While silgen emitFunction SIL function "@$s20PropertyWrapperCrash19TableViewControllerC05tableE0_14didSelectRowAtySo07UITableE0C_10Foundation9IndexPathVtF".
 for 'tableView(_:didSelectRowAt:)' (at /Users/jsbustos/Desktop/Playgrounds/PropertyWrapperCrash/PropertyWrapperCrash/Crashing Files/TableViewController.swift:12:14)
0  swift                    0x000000010df0d3f5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000010df0c6e5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000010df0d9d8 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff70111b5d _sigtramp + 29
4  libsystem_platform.dylib 0x000000011d6b7b76 _sigtramp + 2908381238
5  libsystem_c.dylib        0x00007fff6ffcb6a6 abort + 127
6  swift                    0x000000010e064b8f emitRawApply(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SubstitutionMap, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::Lowering::ApplyOptions, llvm::ArrayRef<swift::SILValue>, llvm::SmallVectorImpl<swift::SILValue>&) (.cold.10) + 223
7  swift                    0x000000010a8bb473 emitRawApply(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SubstitutionMap, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::CanTypeWrapper<swift::SILFunctionType>, swift::Lowering::ApplyOptions, llvm::ArrayRef<swift::SILValue>, llvm::SmallVectorImpl<swift::SILValue>&) + 2387
8  swift                    0x000000010a8bb99c swift::Lowering::SILGenFunction::emitApply(std::__1::unique_ptr<swift::Lowering::ResultPlan, std::__1::default_delete<swift::Lowering::ResultPlan> >&&, swift::Lowering::ArgumentScope&&, swift::SILLocation, swift::Lowering::ManagedValue, swift::SubstitutionMap, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::Lowering::CalleeTypeInfo const&, swift::Lowering::ApplyOptions, swift::Lowering::SGFContext) + 748
9  swift                    0x000000010a8c0345 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3349
10 swift                    0x000000010a8caad2 swift::Lowering::SILGenFunction::emitSetAccessor(swift::SILLocation, swift::SILDeclRef, swift::SubstitutionMap, swift::Lowering::ArgumentSource&&, bool, bool, swift::Lowering::PreparedArguments&&, swift::Lowering::ArgumentSource&&, bool) + 1890
11 swift                    0x000000010a94a32e swift::Lowering::SILGenFunction::emitAssignToLValue(swift::SILLocation, swift::Lowering::ArgumentSource&&, swift::Lowering::LValue&&) + 2078
12 swift                    0x000000010a92b3de emitSimpleAssignment(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Expr*, swift::Expr*) + 990
13 swift                    0x000000010a91a9aa swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 2826
14 swift                    0x000000010a910441 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 1137
15 swift                    0x000000010a97d9dc swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 8796
16 swift                    0x000000010a97b775 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
17 swift                    0x000000010a932615 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 373
18 swift                    0x000000010a8b8cdd swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_0::operator()(swift::SILFunction*) const + 237
19 swift                    0x000000010a8b144d swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 589
20 swift                    0x000000010a988e1f swift::ASTVisitor<(anonymous namespace)::SILGenType, void, void, void, void, void, void>::visit(swift::Decl*) + 623
21 swift                    0x000000010a986a9b (anonymous namespace)::SILGenType::emitType() + 91
22 swift                    0x000000010a986a39 swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 25
23 swift                    0x000000010a8b6436 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 838
24 swift                    0x000000010a8b72fa swift::SILModule::constructSIL(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&, swift::FileUnit*) + 298
25 swift                    0x000000010a8b7736 swift::performSILGeneration(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions&) + 38
26 swift                    0x000000010a5d3dbe performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 7390
27 swift                    0x000000010a5d11b0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3024
28 swift                    0x000000010a578b79 main + 729
29 libdyld.dylib            0x00007fff6ff263d5 start + 1
error: Abort trap: 6 (in target 'PropertyWrapperCrash' from project 'PropertyWrapperCrash')
@JaviSoto
Copy link
Contributor Author

Ah![]( I figured this out. What makes this crash is that the {{wrappedValue}} is typed as {{Value)}} (I did this so that one could reset the value)

@DougGregor
Copy link
Member

Nice find!

@JaviSoto
Copy link
Contributor Author

The attached project no longer crashes the compiler with Xcode 11.4 Beta 2 (Swift 5.2), it actually produces a correct error message:

>Property type 'Bool' does not match that of the 'wrappedValue' property of its wrapper type 'UserDefault<Bool>'

So we can close this 🙂

@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
Projects
None yet
Development

No branches or pull requests

3 participants