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

EarlGrey 2.0 | grey_allOf fails with "Doesn't support pointer returns" #1262

Closed
john-twigg-ck opened this issue Apr 6, 2020 · 7 comments
Closed

Comments

@john-twigg-ck
Copy link

Calling grey_allOf with any arguments fails over the bridge.

        let m = grey_accessibilityID("offers.preapproved")
        let matcher = grey_allOf([ m ]) // throws !!!!

https://github.com/google/eDistantObject/blob/c6d5422f98ada571a8bad727cee67c6845d2f44c/Service/Sources/EDOInvocationMessage.m#L434

else if (EDO_IS_POINTER(returnType)) {
          // TODO(haowoo): Handle this early and populate the exception.

          // We don't/can't support the plain memory access.
          NSAssert(NO, @"Doesn't support pointer returns."); <<<<BOOM!!!
        } 
/// "Doesn't support pointer returns"
 
#0	0x00007fff50b3b982 in objc_exception_throw ()
#1	0x00007fff23e3da48 in +[NSException raise:format:arguments:] ()
#2	0x00007fff258ac792 in -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] ()
#3	0x000000010a1d4265 in __38+[EDOInvocationRequest requestHandler]_block_invoke at /Users/christian.klug/git-repos/stable2/mob_ios/EarlGrey/Submodules/eDistantObject/Service/Sources/EDOInvocationMessage.m:434
#4	0x000000010a1dc314 in __51-[EDOHostService startReceivingRequestsForChannel:]_block_invoke.165 at /Users/christian.klug/git-repos/stable2/mob_ios/EarlGrey/Submodules/eDistantObject/Service/Sources/EDOHostService.m:445
#5	0x000000010a1e5cbc in -[EDOExecutorMessage executeBlock] at /Users/christian.klug/git-repos/stable2/mob_ios/EarlGrey/Submodules/eDistantObject/Service/Sources/EDOExecutorMessage.m:48
#6	0x000000010a1cee2b in -[EDOExecutor loopWithBlock:] at /Users/christian.klug/git-repos/stable2/mob_ios/EarlGrey/Submodules/eDistantObject/Service/Sources/EDOExecutor.m:83
#7	0x000000010a1e0529 in +[EDOClientService sendSynchronousRequest:onPort:withExecutor:] at /Users/christian.klug/git-repos/stable2/mob_ios/EarlGrey/Submodules/eDistantObject/Service/Sources/EDOClientService.m:273
#8	0x000000010a1ca8ae in -[EDOObject(Invocation) edo_forwardInvocation:selector:returnByValue:] at /Users/christian.klug/git-repos/stable2/mob_ios/EarlGrey/Submodules/eDistantObject/Service/Sources/EDOObject+Invocation.m:141
#9	0x000000010a1ca4d9 in -[EDOObject(Invocation) forwardInvocation:] at /Users/christian.klug/git-repos/stable2/mob_ios/EarlGrey/Submodules/eDistantObject/Service/Sources/EDOObject+Invocation.m:106
#10	0x00007fff23e42476 in ___forwarding___ ()
#11	0x00007fff23e449b8 in __forwarding_prep_0___ ()
#12	0x000000010a1adae1 in grey_allOfMatchers at /Users/christian.klug/git-repos/stable2/mob_ios/EarlGrey/AppFramework/Matcher/GREYMatchersShorthand.m:200

@john-twigg-ck
Copy link
Author

It seems to fail the same way in your swift test testButtonPressWithGREYAllOf

PS: I'm running Swift 5, XCode 11.4, iOS 13.4

@john-twigg-ck john-twigg-ck changed the title EarlyGrey 2.0: grey_allOf fails EarlGrey 2.0 | grey_allOf fails with "Doesn't support pointer returns" Apr 7, 2020
@john-twigg-ck
Copy link
Author

john-twigg-ck commented Apr 7, 2020

Done some more digging. This may be a problem with eDistantObject

The problem arrises in iOS 13.4. Swift 5 and Xcode 11.4 are not the culprits I believe as iOS 13.3 seems to work.

The difference thats triggering the error is, for the method selector objectAtIndex , (obviously for the NSArray's that play a role in this call), the Objc Runtime type is different than in previous versions...

char const *returnType = methodSignature.methodReturnType; 
// iOS 13.4:    ^@
// iOS 13.3:    @

in iOS 13.4, this triggers (EDO_IS_POINTER(returnType) and <Kaboom>

@khandpur khandpur assigned khandpur and unassigned khandpur Apr 8, 2020
@AlbertWang0116
Copy link
Collaborator

Hi John,

Thanks for looking into this. As you have figured out, as of iOS 13.4, Swift array declares its objectAtIndex: return type as "pointer to object" (id*) instead of object (id).

I'm surprised of this change, as Swift array's objectAtIndex: doesn't do what it declares now - it still returns you an object (id). It doesn't seem to be a global change to type encoding either, as the signature of my custom method is not changed.

I'm still looking at if there's any other side effects which are related to this. If you want to be unblocked right away, you can switch to NSArray when dealing with EarlGrey's API, such as grey_allOf. For example:

let matcherArray : NSArray = [grey_text("foo"), grey_sufficientlyVisible()]
let matcher = grey_allOf(matcherArray)

@wuhao5
Copy link
Contributor

wuhao5 commented Apr 9, 2020

let matcher = grey_allOf([ m ]) // throws !!!!

You can't really use Swift type as a remote object, because Swift does runtime checks in general. It shouldn't work and in Swift 5 it might have patched the hole to define Swift array more strict. The best way to fire a remote method is through @objc protocols, where Swift won't do the runtime check and goes thru the runtime dispatching machinery like what happens in ObjC. So what you can do, as mentioned by @AlbertWang0116 , is

grey_allOf(NSArray.init(array:[NSObject.init(), NSObject.init()]))

@john-twigg-ck
Copy link
Author

john-twigg-ck commented Apr 24, 2020

Here's my workaround solution for the time being, once which I happen to like anyways...

extension Sequence where Element == GREYMatcher {
    /// Use this instead of grey_allOf.
    /// Ex: [grey_accessibilityId(...), grey_buttonTitle(...)].all()
    /// - Returns: grey_allOf matcher
    func all() -> GREYMatcher {
        let m: [GREYMatcher] = self.map { $0 }
        // https://github.com/google/EarlGrey/issues/1262
        // swiftlint:disable:next force_cast
        return grey_allOf(NSArray(array: m) as! [GREYMatcher])
    }

    
    /// Use this instead of grey_anyOf.
    /// Ex: [grey_accessibilityId(...), grey_buttonTitle(...)].any()
    /// - Returns:grey_anyOf matcher
    func any() -> GREYMatcher {
        let m: [GREYMatcher] = self.map { $0 }
        // https://github.com/google/EarlGrey/issues/1262
        // swiftlint:disable:next force_cast
        return grey_anyOf(NSArray(array: m) as! [GREYMatcher])
    }
}

@shaneong
Copy link

shaneong commented Dec 6, 2020

Any possibility of merging this as a permanent solution?

@AlbertWang0116
Copy link
Collaborator

This is fixed by EarlGrey 2.2.1 release/eDO 1.0.2 release so you don't need the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants