Bug 23478 - Incorrect behavior of 'as' operator for interfaces with covariant type parameters when using full AOT
Summary: Incorrect behavior of 'as' operator for interfaces with covariant type parame...
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 8.2.0
Hardware: PC All
: Normal normal
Target Milestone: Untriaged
Assignee: Zoltan Varga
URL:
Depends on:
Blocks:
 
Reported: 2014-09-30 02:09 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2014-11-26 09:30 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test case (7.86 KB, application/zip)
2014-09-30 02:09 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Brendan Zagaeski (Xamarin Team, assistant) 2014-09-30 02:09:24 UTC
Created attachment 8249 [details]
Test case

Incorrect behavior of 'as' operator for interfaces with covariant type parameters when using full AOT


In the attached test case, the conversion `var extCovariant = covariant as IExtCovariant<IMyInterface>` should return `null`, but on hardware iOS devices it does not.

This might be somehow related to bug 15186.


## Steps to reproduce

Build and run the attached test case on a hardware iOS device. (Tested in the Debug configuration on an iPhone 4s, iOS 7.1.2)


## Result

The UILabel in the center of the screen shows "Wrong!", indicating that the conversion `covariant as IExtCovariant<IMyInterface>` returned a non-null value. This is incorrect because `covariant` is of type `Sample<IMyInterface>` and `Sample<IMyInterface>` is *not* a descendent of `IExtCovariant<IMyInterface>`.


On iOS simulators the result is always "Right." The result is also always "Right" if you copy the logic over into a Mono or .NET desktop app.


## Ways to stop the problem in the test case

a. Remove the `(object)` cast in this line:
> var foo = (ICovariant<IMyInterface>)((object)covariant);

OR

b. Remove the `out` modifier from the type parameters for `IExtCovariant<out R>`.


## Version information
Xamarin.iOS 8.2.0.187 (Business Edition)
Hash: a1f0a7a
Build date: 2014-09-27 22:06:24-0400

Mono 3.10.0 ((detached/53e3161)

Xamarin Studio 5.5 (build 222)
Git revision: dae37674f8a41572a91bf0e14c098d15e03d0a53
Xamarin addins: bab982129fe7697d3c639fa713751ab29305a257

Xcode 6.0.1 (6528), Build 6A317
Mac OS X 10.9.4
Comment 2 Shruti 2014-09-30 03:29:44 UTC
I have checked this issue with attached TestCase sample Project and able to reproduce it.  I observed that When app is deployed on device with syntax 'var foo = (ICovariant<IMyInterface>)((object)covariant);', it is displaying result 'Wrong'. When I removed cast 'Object' and deployed  app on device then it has given result 'Right'. 

Environment Info :
=== Xamarin Studio ===

Version 5.5 (build 222)
Installation UUID: 45555ffd-f3f0-4f29-9543-e369d711ab7d
Runtime:
	Mono 3.10.0 ((detached/53e3161)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000018

=== Apple Developer Tools ===

Xcode 6.0.1 (6528)
Build 6A317

=== Xamarin.Mac ===

Version: 1.11.0.1 (Starter Edition)

=== Xamarin.iOS ===

Version: 8.2.0.187 (Trial Edition)
Hash: a1f0a7a
Branch: 
Build date: 2014-09-27 22:06:24-0400

=== Xamarin.Android ===

Version: 4.18.0 (Starter Edition)
Android SDK: /Users/xamarin77/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		4.5    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Build Information ===

Release ID: 505000222
Git revision: dae37674f8a41572a91bf0e14c098d15e03d0a53
Build date: 2014-09-26 14:15:04-04
Xamarin addins: bab982129fe7697d3c639fa713751ab29305a257

=== Operating System ===

Mac OS X 10.9.5
Darwin Xamarin77s-Mac-mini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 3 Rolf Bjarne Kvinge [MSFT] 2014-09-30 05:20:58 UTC
Zoltan, can you have a look?
Comment 4 Zoltan Varga 2014-09-30 22:14:39 UTC
Fixed in mono master fc7c8e976562012fee04d1bd2422461bc24b5e19, bumped mt master to it in da8cbee110459fc04e16de7e6e229e4bdfc56ee4.
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2014-09-30 23:06:40 UTC
Thanks for the quick fix!
Comment 6 Sunil Kumar 2014-11-26 09:30:51 UTC
I have checked this issue with attached TestCase sample Project and now it's working fine. It displays result 'Right' in both cases when app is deployed on device with syntax 'var foo = (ICovariant<IMyInterface>)((object)covariant);'  and When I removed cast 'Object' and deployed  app on device.

Environment info:
Device: iPhone 5s iOS 7.1

=== Xamarin Studio ===

Version 5.7 (build 596)
Installation UUID: 561c7a69-0a91-4bae-ad7c-f0c79d594337
Runtime:
	Mono 3.12.0 ((detached/b75fa2b)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000046

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: 8.6.0.5 (Trial Edition)
Hash: 880cc21
Branch: 
Build date: 2014-11-25 12:12:17-0500

=== Xamarin.Android ===

Version: 5.0.0.0 (Trial Edition)
Android SDK: /Users/tajinder/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: 1.11.1.201 (Indie Edition)

=== Build Information ===

Release ID: 507000596
Git revision: d996e9ba6874a0d64241e43e5e6b06322ce29c84
Build date: 2014-11-25 17:17:54-05
Xamarin addins: 8ca19707b41536a391f53364ee4ff9272711feb0

=== Operating System ===

Mac OS X 10.8.4
Darwin Tajinders-iMac.local 12.4.2 Darwin Kernel Version 12.4.2
    Mon Jun 17 18:00:12 PDT 2013
    root:xnu-2050.45.8~1/RELEASE_X86_64 x86_64