Cuckoo icon indicating copy to clipboard operation
Cuckoo copied to clipboard

Throwing "'some' types are only permitted in properties, subscripts, and functions" when `func` throws & has `some` for its parameter

Open enebin opened this issue 1 year ago • 2 comments

First, I'd like to say I've really appreciated your works. It's pure amazement. However, there're a few issues blocking me to do further tasks. I brought some infos about it.

Reproducing code is here:

import SwiftUI

class SomeClass {
    func someMethod(_: some UIViewRepresentable) throws {
        
    }
}

It generates:

 struct __StubbingProxy_SomeClass: Cuckoo.StubbingProxy {
        private let cuckoo_manager: Cuckoo.MockManager
    
         init(manager: Cuckoo.MockManager) {
            self.cuckoo_manager = manager
        }
        
        
        
        
        func someMethod<M1: Cuckoo.Matchable>(_ parameter0: M1) -> Cuckoo.ClassStubNoReturnThrowingFunction<(some UIViewRepresentable)> where M1.MatchedType == some UIViewRepresentable {
            let matchers: [Cuckoo.ParameterMatcher<(some UIViewRepresentable)>] = [wrap(matchable: parameter0) { $0 }]
            return .init(stub: cuckoo_manager.createStub(for: MockSomeClass.self, method:
    """
    someMethod(_: some UIViewRepresentable) throws
    """, parameterMatchers: matchers))
        }
        
        
    }

and


 class MockSomeClass: SomeClass, Cuckoo.ClassMock {
    
     typealias MocksType = SomeClass
    
     typealias Stubbing = __StubbingProxy_SomeClass
     typealias Verification = __VerificationProxy_SomeClass

     let cuckoo_manager = Cuckoo.MockManager.preconfiguredManager ?? Cuckoo.MockManager(hasParent: true)

    
    private var __defaultImplStub: SomeClass?

     func enableDefaultImplementation(_ stub: SomeClass) {
        __defaultImplStub = stub
        cuckoo_manager.enableDefaultStubImplementation()
    }
    

    

    

    
    
    
    
     override func someMethod(_ parameter0: some UIViewRepresentable) throws {
        
    return try cuckoo_manager.callThrows(
    """
    someMethod(_: some UIViewRepresentable) throws
    """,
            parameters: (parameter0),
            escapingParameters: (parameter0),
            superclassCall:
                
                super.someMethod(parameter0)
                ,
            defaultCall: __defaultImplStub!.someMethod(parameter0))
        
    }
    
    

     struct __StubbingProxy_SomeClass: Cuckoo.StubbingProxy {
        private let cuckoo_manager: Cuckoo.MockManager
    
         init(manager: Cuckoo.MockManager) {
            self.cuckoo_manager = manager
        }
        
        
        func someMethod<M1: Cuckoo.Matchable>(_ parameter0: M1) -> Cuckoo.ClassStubNoReturnThrowingFunction<(some UIViewRepresentable)> where M1.MatchedType == some UIViewRepresentable {
            let matchers: [Cuckoo.ParameterMatcher<(some UIViewRepresentable)>] = [wrap(matchable: parameter0) { $0 }]
            return .init(stub: cuckoo_manager.createStub(for: MockSomeClass.self, method:
    """
    someMethod(_: some UIViewRepresentable) throws
    """, parameterMatchers: matchers))
        }
        
        
    }

     struct __VerificationProxy_SomeClass: Cuckoo.VerificationProxy {
        private let cuckoo_manager: Cuckoo.MockManager
        private let callMatcher: Cuckoo.CallMatcher
        private let sourceLocation: Cuckoo.SourceLocation
    
         init(manager: Cuckoo.MockManager, callMatcher: Cuckoo.CallMatcher, sourceLocation: Cuckoo.SourceLocation) {
            self.cuckoo_manager = manager
            self.callMatcher = callMatcher
            self.sourceLocation = sourceLocation
        }
    
        @discardableResult
        func someMethod<M1: Cuckoo.Matchable>(_ parameter0: M1) -> Cuckoo.__DoNotUse<(some UIViewRepresentable), Void> where M1.MatchedType == some UIViewRepresentable {
            let matchers: [Cuckoo.ParameterMatcher<(some UIViewRepresentable)>] = [wrap(matchable: parameter0) { $0 }]
            return cuckoo_manager.verify(
    """
    someMethod(_: some UIViewRepresentable) throws
    """, callMatcher: callMatcher, parameterMatchers: matchers, sourceLocation: sourceLocation)
        }
        
        
    }
}

and throws 'some' types are only permitted in properties, subscripts, and functions like the screenshot I attached below: image

Could you check it once?

enebin avatar Jun 10 '23 10:06 enebin

Hey there, @enebin! Thanks for bringing this to light. I'd like to improve the way Cuckoo works with types altogether, so it helps knowing of this case I need to think about. 🙂

MatyasKriz avatar Jun 12 '23 16:06 MatyasKriz

I admit that I completely forgot about this case, but it seems like a good addition to the project. If you're willing to contribute, I'd gladly merge it! 🙂

MatyasKriz avatar Apr 23 '24 15:04 MatyasKriz