@@ -50,13 +50,36 @@ abstract private class GeneratedType extends Type, GeneratedElement {
5050 }
5151
5252 /**
53- * Holds if this type is duplicated in another assembly.
54- * In this case, we use the assembly with the highest string.
53+ * Holds if this type is defined in multiple assemblies, and at least one of
54+ * them is in the `Microsoft.NETCore.App.Ref` folder. In this case, we only stub
55+ * the type in the assembly in `Microsoft.NETCore.App.Ref`. In case there are
56+ * multiple assemblies in this folder, then we prefer `System.Runtime`.
5557 */
56- private predicate isDuplicate ( ) {
57- exists ( GeneratedType dup |
58- dup .getQualifiedName ( ) = this .getQualifiedName ( ) and
59- this .getLocation ( ) .( Assembly ) .toString ( ) < dup .getLocation ( ) .( Assembly ) .toString ( )
58+ private predicate isDuplicate ( Assembly assembly ) {
59+ // type exists in multiple assemblies
60+ count ( this .getALocation ( ) .( Assembly ) ) > 1 and
61+ // at least one of them is in the `Microsoft.NETCore.App.Ref` folder
62+ this .getALocation ( )
63+ .( Assembly )
64+ .getFile ( )
65+ .getAbsolutePath ( )
66+ .matches ( "%Microsoft.NETCore.App.Ref%" ) and
67+ exists ( int i |
68+ i =
69+ count ( Assembly a |
70+ this .getALocation ( ) = a and
71+ a .getFile ( ) .getAbsolutePath ( ) .matches ( "%Microsoft.NETCore.App.Ref%" )
72+ )
73+ |
74+ i = 1 and
75+ // assemblies not in `Microsoft.NETCore.App.Ref` folder are considered duplicates
76+ not assembly .getFile ( ) .getAbsolutePath ( ) .matches ( "%Microsoft.NETCore.App.Ref%" )
77+ or
78+ i > 1 and
79+ // one of the assemblies is named `System.Runtime`
80+ this .getALocation ( ) .( Assembly ) .getName ( ) = "System.Runtime" and
81+ // all others are considered duplicates
82+ assembly .getName ( ) != "System.Runtime"
6083 )
6184 }
6285
@@ -104,8 +127,11 @@ abstract private class GeneratedType extends Type, GeneratedElement {
104127
105128 /** Gets the entire C# stub code for this type. */
106129 final string getStub ( Assembly assembly ) {
107- if this .isDuplicate ( )
108- then result = ""
130+ if this .isDuplicate ( assembly )
131+ then
132+ result =
133+ "/* Duplicate type '" + this .getName ( ) + "' is not stubbed in this assembly '" +
134+ assembly .toString ( ) + "'. */\n\n"
109135 else (
110136 not this instanceof DelegateType and
111137 result =
0 commit comments