Commit 3343634
[generator] Only skip generic "overloads" of bound types (#178)
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=57828
The #runtime team is attempting to update xamarin-android to use the
[mono/2017-06][0] and [mono/2017-08][1] (and...) branches, and when
doing so they are seeing a unit test fail in
`Xamarin.Android.Build.Tests.BuildTest.GeneratorValidateMultiMethodEventName()`:
no `BG850*` warnings are expected but they are produced.
After much analysis, the cause of ght `BG850*` warnings is that
the mono/2017-06 branch introduces a non-generic "overload" of
`System.Collections.Generic.KeyValuePair`:
namespace System.Collections.Generic {
// New with mono/2017-06
partial class KeyValuePair {
public static KeyValuePair<TKey, TValue> Create<TKey, TValue>(TKey key, TValue value);
}
// Existing since forever
partial struct KeyValuePair<TKey, TValue> {
}
}
Specifically, the above "`KeyValuePair` overload" type runs into a
FIXME within `CodeGenerator.cs`:
// FIXME: at some stage we want to import generic types.
// For now generator fails to load generic types that have conflicting type e.g.
// AdapterView`1 and AdapterView cannot co-exist.
// It is mostly because generator primarily targets jar (no real generics land).
The *intent* of the check that is that, given a type `AdapterView<T>`,
we only check to see if `AdapterView` exists as well. If it does exist,
then we *ignore* the `AdapterView<T>` type, and only use the
`AdapterView` type for code generation.
In the case of `KeyValuePair`, the same "check" is done, which cause
us to *skip* type registration for `KeyValuePair<TKey, TValue>`, which
in turn causes us to invalidate e.g. `IDictionary<TKey, TValue>` -- as
it implements `ICollection<KeyValuePair<TKey, TValue>>` -- and
everything promply falls apart from there:
warning BG8C00: For type System.Collections.Generic.IDictionary`2, base interface System.Collections.Generic.ICollection`1<System.Collections.Generic.KeyValuePair`2<TKey,TValue>> is invalid.
warning BG8C00: For type System.Collections.Generic.IDictionary`2, base interface System.Collections.Generic.IEnumerable`1<System.Collections.Generic.KeyValuePair`2<TKey,TValue>> is invalid.
warning BG8502: Invalidating System.Collections.Generic.IDictionary`2 and all nested types because some of its interfaces were invalid.
warning BG8801: Invalid parameter type System.Collections.Generic.IDictionary`2<System.String,System.Collections.Generic.IList`1<System.String>> in method MapEquivalents in managed type Java.Util.Locale.LanguageRange.
warning BG8801: Invalid parameter type System.Collections.Generic.IDictionary`2<System.String,System.Collections.Generic.IList`1<System.String>> in method Parse in managed type Java.Util.Locale.LanguageRange.
warning BG8801: Invalid parameter type System.Collections.Generic.IDictionary`2<System.String,System.Object> in method NewFileSystem in managed type Java.Nio.FileNio.Spi.FileSystemProvider.
warning BG8801: Invalid parameter type System.Collections.Generic.IDictionary`2<System.String,System.Object> in method NewFileSystem in managed type Java.Nio.FileNio.Spi.FileSystemProvider.
warning BG8801: Invalid parameter type System.Collections.Generic.IDictionary`2<System.String,System.String> in method .ctor in managed type Java.Security.Provider.Service.
warning BG8801: Invalid parameter type System.Collections.Generic.IDictionary`2<System.Object,System.Object> in method PutAll in managed type Java.Security.Provider.
I still don't fully understand the scenario that the check was
attempting to solve, so in lieu of actually fixing the FIXME, make the
check *stricter* so that we only ignore "generically overloaded" types
if they bind the *same* Java type. Since `KeyValuePair<TKey, TValue>`
binds *no* Java type, it will no longer be skipped, thus removing the
BG8502 and related warnings.
Additionally, a bit of code cleanup for consistency: some parts of the
code use `HAVE_CECIL`, and others use `USE_CECIL`. Standardize on
`HAVE_CECIL` for consistency and sanity.
[0]: dotnet/android#631
[1]: dotnet/android#7231 parent 1cd0361 commit 3343634
File tree
11 files changed
+38
-25
lines changed- src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings
- tools/generator
11 files changed
+38
-25
lines changedLines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
255 | | - | |
| 255 | + | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
387 | | - | |
| 387 | + | |
388 | 388 | | |
389 | 389 | | |
390 | 390 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
262 | 263 | | |
263 | 264 | | |
264 | 265 | | |
265 | | - | |
266 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
267 | 270 | | |
268 | 271 | | |
269 | 272 | | |
| |||
366 | 369 | | |
367 | 370 | | |
368 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
369 | 381 | | |
370 | 382 | | |
371 | 383 | | |
| |||
404 | 416 | | |
405 | 417 | | |
406 | 418 | | |
407 | | - | |
| 419 | + | |
408 | 420 | | |
409 | 421 | | |
410 | 422 | | |
| |||
434 | 446 | | |
435 | 447 | | |
436 | 448 | | |
437 | | - | |
| 449 | + | |
438 | 450 | | |
439 | 451 | | |
440 | 452 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
| 287 | + | |
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
300 | | - | |
| 300 | + | |
301 | 301 | | |
302 | 302 | | |
0 commit comments