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

x/mobile/cmd/gomobile: type conversion not working on iOS #17369

Open
jotdl opened this issue Oct 6, 2016 · 0 comments
Open

x/mobile/cmd/gomobile: type conversion not working on iOS #17369

jotdl opened this issue Oct 6, 2016 · 0 comments
Labels
mobile Android, iOS, and x/mobile
Milestone

Comments

@jotdl
Copy link

jotdl commented Oct 6, 2016

Hey,

I have a (hopefully small) issue with type conversion related to usage of gomobile:

What version of Go are you using (go version)?

go version go1.7.1 darwin/amd64
gomobile version +6ea0bb5 Wed Oct 5 13:16:13 2016 +0000 (android,ios); androidSDK=/Users/.../Library/Android/sdk/platforms/android-23

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"

What did you do?

  1. Write code with composed interface. Can be something like
type Car interface {
    WheelCount() int
}
type Limousine interface {
    Car
    Seats() int
    SetSeats(seats int)
}

Full go code is available at Go Code
2. Generate go mobile bindings for iOS and android, e.g.
gomobile bind -target=ios data
3. Create platform specific app and call a go method which tries to do type conversion. Type conversion may be:

func PrintCar(car Car) {
    fmt.Println("Car: ", car)
    fmt.Println("Wheels: ", car.WheelCount())

    limousine, ok := car.(Limousine)
    fmt.Println("Limousine cast was ", ok, ", Content:", limousine)
    if ok {
        fmt.Println("Seats: ", limousine.Seats())
    }
}

and platform specific code like this for iOS

id<GoDataLimousine> car = GoDataNewLimousine();
[car setSeats:5];
GoDataPrintCar(car);
  1. Execute the program on iOS or Android

What did you expect to see?

Type conversion from Car to Limousine should be possible if the object fulfills Limousine.
Output of type conversion on Go, iOS and Android:

Car:  &{4 5}
Wheels:  4
Limousine cast was  true , Content: &{4 5}
Seats:  5

What did you see instead?

Type conversion is not possible on iOS between interfaces. Output of type conversion Go, Android (as expected):

Car:  &{4 5}
Wheels:  4
Limousine cast was  true , Content: &{4 5}
Seats:  5

iOS, fails to do type conversion. The limousine is stripped down to fulfill the car interface only and does not fulfill the limousine interface anymore:

Car:  &{42}
Wheels:  4
Limousine cast was  false , Content: <nil>

So in my understanding type conversion should work on iOS as it does on android and in normal go itself. But using gomobile on iOS, interfaces seem to loose other fulfilled interfaces once they're passed to a method which receives a specific interface only.

Or am I doing something wrong? Otherwise I would like to help solving this issue. Sadly I am new to the go mobile tooling itself. Maybe somebody can point me into the right direction?

Is this intentionally not working or is it expected to work?

Thanks for your help!

@quentinmit quentinmit added this to the Unreleased milestone Oct 6, 2016
@jotdl jotdl changed the title x/mobile/cmd/gomobile: type conversion differs on android and iOS x/mobile/cmd/gomobile: type conversion not working on iOS Oct 8, 2016
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jul 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile
Projects
None yet
Development

No branches or pull requests

3 participants