@@ -1946,32 +1946,52 @@ mono_class_interface_offset (MonoClass *klass, MonoClass *itf)
1946
1946
int
1947
1947
mono_class_interface_offset_with_variance (MonoClass * klass , MonoClass * itf , gboolean * non_exact_match )
1948
1948
{
1949
- int i = mono_class_interface_offset (klass , itf );
1949
+ // const char *iname = mono_type_get_name_full (m_class_get_byval_arg (itf), MONO_TYPE_NAME_FORMAT_FULL_NAME);
1950
+ gboolean has_variance = mono_class_has_variant_generic_params (itf );
1951
+ int exact_match = mono_class_interface_offset (klass , itf ), i = -1 ;
1950
1952
* non_exact_match = FALSE;
1951
- if (i >= 0 )
1952
- return i ;
1953
+
1954
+ if (exact_match >= 0 ) {
1955
+ // g_print ("exact match for %s on %s\n", iname, m_class_get_name (klass));
1956
+ if (!has_variance )
1957
+ return exact_match ;
1958
+ }
1953
1959
1954
1960
int klass_interface_offsets_count = m_class_get_interface_offsets_count (klass );
1955
1961
1956
1962
if (m_class_is_array_special_interface (itf ) && m_class_get_rank (klass ) < 2 ) {
1957
1963
MonoClass * gtd = mono_class_get_generic_type_definition (itf );
1958
1964
int found = -1 ;
1959
1965
1960
- for (i = 0 ; i < klass_interface_offsets_count ; i ++ ) {
1966
+ for (i = klass_interface_offsets_count - 1 ; i >= 0 ; i -- ) {
1961
1967
if (mono_class_is_variant_compatible (itf , m_class_get_interfaces_packed (klass ) [i ], FALSE)) {
1968
+ /*
1969
+ g_print (
1970
+ "is_variant_compatible (%s, %s, FALSE) == true\n",
1971
+ iname,
1972
+ mono_type_get_name_full (m_class_get_byval_arg (m_class_get_interfaces_packed (klass) [i]), MONO_TYPE_NAME_FORMAT_FULL_NAME)
1973
+ );
1974
+ */
1962
1975
found = i ;
1963
- * non_exact_match = TRUE ;
1976
+ * non_exact_match = ( i != exact_match ) ;
1964
1977
break ;
1965
1978
}
1966
1979
1967
1980
}
1968
1981
if (found != -1 )
1969
1982
return m_class_get_interface_offsets_packed (klass ) [found ];
1970
1983
1971
- for (i = 0 ; i < klass_interface_offsets_count ; i ++ ) {
1984
+ for (i = klass_interface_offsets_count - 1 ; i >= 0 ; i -- ) {
1972
1985
if (mono_class_get_generic_type_definition (m_class_get_interfaces_packed (klass ) [i ]) == gtd ) {
1986
+ /*
1987
+ g_print (
1988
+ "gtd_of (%s) == gtd_of (%s)\n",
1989
+ mono_type_get_name_full (m_class_get_byval_arg (m_class_get_interfaces_packed (klass) [i]), MONO_TYPE_NAME_FORMAT_FULL_NAME),
1990
+ iname
1991
+ );
1992
+ */
1973
1993
found = i ;
1974
- * non_exact_match = TRUE ;
1994
+ * non_exact_match = ( i != exact_match ) ;
1975
1995
break ;
1976
1996
}
1977
1997
}
@@ -1982,12 +2002,19 @@ mono_class_interface_offset_with_variance (MonoClass *klass, MonoClass *itf, gbo
1982
2002
return m_class_get_interface_offsets_packed (klass ) [found ];
1983
2003
}
1984
2004
1985
- if (!mono_class_has_variant_generic_params ( itf ) )
2005
+ if (!has_variance )
1986
2006
return -1 ;
1987
2007
1988
- for (i = 0 ; i < klass_interface_offsets_count ; i ++ ) {
2008
+ for (i = klass_interface_offsets_count - 1 ; i >= 0 ; i -- ) {
1989
2009
if (mono_class_is_variant_compatible (itf , m_class_get_interfaces_packed (klass ) [i ], FALSE)) {
1990
- * non_exact_match = TRUE;
2010
+ /*
2011
+ g_print (
2012
+ "is_variant_compatible (%s, %s, FALSE) == true\n",
2013
+ iname,
2014
+ mono_type_get_name_full (m_class_get_byval_arg (m_class_get_interfaces_packed (klass) [i]), MONO_TYPE_NAME_FORMAT_FULL_NAME)
2015
+ );
2016
+ */
2017
+ * non_exact_match = (i != exact_match );
1991
2018
return m_class_get_interface_offsets_packed (klass ) [i ];
1992
2019
}
1993
2020
}
0 commit comments