Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Re-entrant implicit operator
Message
From
08/08/2016 05:55:11
 
 
To
08/08/2016 05:34:51
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01639212
Message ID:
01639216
Views:
55
>>Interesting bit of bad code which the compiler does not catch and which causes stack overflow because it is re-entrant:
static void Main(string[] args)
>>        {
>>            Test test = "Hello World";
>>        }
>>
>>    public class Test
>>    {
>>        public static implicit operator Test(string s)
>>        {
>>            return s; // obviously wrong but compiles and is re-entrant when run
>>        }
>>    }
>
>I think the problem is that the operator does not return an instance of Test
>
>Maybe something like this
>
>	public class Test
>	{
>		public string Value { get; private set; }
>		public Test(string s)
>		{
>			this.Value = s;
>		}
>		public static implicit operator Test(string s)
>		{
>			return new Test(s); // obviously wrong but compiles and is re-entrant when run
>		}
>	}
>
Yea. I knew how it was supposed to be. Just surprised that my intial 'typo' was allowed and gave the results that it did.....
Previous
Reply
Map
View

Click here to load this message in the networking platform