-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic type resolution goes into infinite recursion #16908
Comments
Here's another repro - this also causes StackOverflowException: class First<T> where T : First<T> { }
class Second<T> : First<T> where T : First<T> { }
class Third<T> : Second<Third<T>> { }
class Program
{
static void Main()
{
dynamic x = new Third<int>();
Print(x); // Uncomment this and the exception goes away.
}
static void Print(object obj) { }
} Also see: http://stackoverflow.com/questions/39870305/system-stackoverflowexception-error-when-try-to-get-a-dynamic-proppery-from-an#comment67032482_39870305 [EDIT] Add C# syntax highlighting by @karelz |
We need someone to get it under debugger and find out what is wrong in .NET Core code. |
The loop is straight-forward enough. In the last of the examples produced, for example, it trys to substitute the types in Breaking the loop does not seem to be easy though. |
There is duplicate report in dotnet/corefx#23706 with variant of the same bug:
Note: The original (previously "hidden") repro does not have any constraints on generic parameters. |
Push logic for calculating the substitution necessary on base types when type or the base are generic into AggregateType and defer it until first call. This allows cycling chains of derivation and type parameters. Fixes #7527
Confirms fix for #7527 also fixes #23706
The great thing about not having time to contribute to corefx for a month, is getting a fresher look at some things. I'd tried a variant of the fix in dotnet/corefx#25196 before but must have slipped up, since it went quite smoothly this time. |
Push logic for calculating the substitution necessary on base types when type or the base are generic into AggregateType and defer it until first call. This allows cycling chains of derivation and type parameters. Fixes #7527
Confirms fix for #7527 also fixes #23706
Push logic for calculating the substitution necessary on base types when type or the base are generic into AggregateType and defer it until first call. This allows cycling chains of derivation and type parameters. Fixes #7527
Confirms fix for #7527 also fixes #23706
Push logic for calculating the substitution necessary on base types when type or the base are generic into AggregateType and defer it until first call. This allows cycling chains of derivation and type parameters. Fixes #7527
Confirms fix for #7527 also fixes #23706
…#25196) * Defer calculation of AggregateType.GetBaseClass() Push logic for calculating the substitution necessary on base types when type or the base are generic into AggregateType and defer it until first call. This allows cycling chains of derivation and type parameters. Fixes #7527 * Add test for variant of cyclic type definitions. Confirms fix for #7527 also fixes #23706 * Overrides SubstType and SubstTypeCore for AggregateType when used In one case replaces the equivalent existing override completely. Allows type-checking and casting to be avoided. * Test another variant of #7527 Based on https://stackoverflow.com/q/19612325/400547
It might be worth making this netfx-port-consider, since there are several stackoverflow questions about it with netfx, suggesting it affects a fair number of people. |
@JonHanna did you see more than the 2 StackOverflow links above? If there are any highly upvoted, that would be worth linking from here. It will be useful at the point we do the port to assess need vs. risk. Thanks! |
There was also https://stackoverflow.com/q/19612325/400547 that gave me the idea of testing it in cases where it should throw RBE. |
Which last one? Can you please edit your reply to keep just the relevant links? Thanks! |
NP |
Under certain circumstances dynamic type resolution goes into infinite recursion (causing program to terminate with StackOverflowException) alternating between these methods:
This happens only when an argument of type "dynamic" is passed, of course. Static typing works fine.
Repro:
[EDIT] Fixed callstack formatting by @karelz
[EDIT] Inlined source code from original attachment repro.txt, with minor formatting changes by @karelz
The text was updated successfully, but these errors were encountered: