Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
iskiselev committed Jul 22, 2016
2 parents ca0eabc + 05aa209 commit 84c476e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
23 changes: 22 additions & 1 deletion JSIL/DefinitelyTypedAssemblyEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ public static bool WriteTypeReference (this JavascriptFormatter formatter, TypeR
* It could be improved, by we really need generic variance support or support of:
type T = something & I<T> (see Microsoft/TypeScript#6230)
*/
var fixedMode = (replaceMode != ReplaceMode.Instance && context == definition) ? ReplaceMode.Instance : replaceMode;
var fixedMode = (replaceMode != ReplaceMode.Instance && IsCircularRef(definition, context)) ? ReplaceMode.Instance : replaceMode;
formatter.TRSuffix(fixedMode);
}
else {
Expand All @@ -639,6 +639,27 @@ public static bool WriteTypeReference (this JavascriptFormatter formatter, TypeR
return true;
}

public static bool IsCircularRef (TypeReference type, TypeDefinition context) {
if (type is GenericParameter) {
return false;
}
if (type is ArrayType) {
return IsCircularRef(((ArrayType) type).ElementType, context);
}
if (type is GenericInstanceType) {
var gt = (GenericInstanceType) type;
foreach (var genericArgument in gt.GenericArguments) {
if (IsCircularRef(genericArgument, context)) {
return true;
}
}
}
if (type.Resolve() == context) {
return true;
};
return false;
}

public static void CommaSeparatedList<T> (this JavascriptFormatter formatter, IEnumerable<T> list, Action<T> process) {
bool first = true;
foreach (var item in list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ public static void Main()
{
Expression<Action> exp = () => Method1<Test>();
var returnType = ((MethodCallExpression)exp.Body).Method.ReturnType;
Console.WriteLine(returnType.GetType().FullName);
Console.WriteLine(returnType.GetType().IsSubclassOf(typeof(Type)) ? "true" : "false");
Console.WriteLine(typeof(Test) == returnType ? "true" : "false");

exp = () => Method1<int>();
returnType = ((MethodCallExpression)exp.Body).Method.ReturnType;
Console.WriteLine(returnType.GetType().FullName);
Console.WriteLine(returnType.GetType().IsSubclassOf(typeof(Type)) ? "true" : "false");
Console.WriteLine(typeof(int) == returnType ? "true" : "false");

exp = () => Method2<Test>();
returnType = ((MethodCallExpression)exp.Body).Method.ReturnType;
Console.WriteLine(returnType.GetType().FullName);
Console.WriteLine(returnType.GetType().IsSubclassOf(typeof(Type)) ? "true" : "false");
Console.WriteLine(typeof(Holder<Test>) == returnType ? "true" : "false");

exp = () => Method2<int>();
returnType = ((MethodCallExpression)exp.Body).Method.ReturnType;
Console.WriteLine(returnType.GetType().FullName);
Console.WriteLine(returnType.GetType().IsSubclassOf(typeof(Type)) ? "true" : "false");
Console.WriteLine(typeof(Holder<int>) == returnType ? "true" : "false");

exp = () => Method3<Test>();
returnType = ((MethodCallExpression)exp.Body).Method.ReturnType;
Console.WriteLine(returnType.GetType().FullName);
Console.WriteLine(returnType.GetType().IsSubclassOf(typeof(Type)) ? "true" : "false");
Console.WriteLine(typeof(Test[]) == returnType ? "true" : "false");

exp = () => Method3<int>();
returnType = ((MethodCallExpression)exp.Body).Method.ReturnType;
Console.WriteLine(returnType.GetType().FullName);
Console.WriteLine(returnType.GetType().IsSubclassOf(typeof(Type)) ? "true" : "false");
Console.WriteLine(typeof(int[]) == returnType ? "true" : "false");
}

Expand Down

0 comments on commit 84c476e

Please sign in to comment.