You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingSystem;usingSystem.Threading.Tasks;_=Foo.NumberBuggy().Result;Console.WriteLine("--------");_=Foo.NumberNotBuggy();publicclassFoo{publicstaticasyncTask<int>NumberBuggy(){stringstr="a2";intx=1;inty=2;refintr=refawaitEvalAsync(str,1)is"a1"?refx:refawaitEvalAsync(str,2)is"a2"?refy:refSystem.Runtime.CompilerServices.Unsafe.NullRef<int>();r++;r++;r++;intxxx=r;System.Console.WriteLine(xxx);System.Console.WriteLine(x);System.Console.WriteLine(y);//should be 5 now!returnxxx;}publicstaticValueTask<int>NumberNotBuggy(){stringstr="a2";intx=1;inty=2;refintr=refEvalAsync(str,1).Resultis"a1"?refx:refEvalAsync(str,2).Resultis"a2"?refy:refSystem.Runtime.CompilerServices.Unsafe.NullRef<int>();r++;r++;r++;intxxx=r;System.Console.WriteLine(xxx);System.Console.WriteLine(x);System.Console.WriteLine(y);returnnew(xxx);}staticValueTask<string>EvalAsync(strings,inti){System.Console.WriteLine($"{s}{i}");returnValueTask.FromResult(s);}}
Expected Behavior:
Same output for both methods (they are not really async)
Actual Behavior:
The result of the conditional expression is stored in a non-ref temp local which causes that the later increment operations do not change the original value - just the temp.
bernd5
changed the title
Bug: Conditional Expression stores ref result in non ref local temp (Only when Spillseq
Bug: Conditional Expression stores ref result in non ref local temp (Only when SpillSequenceSpiller is used - e.g. for async/await)
Jun 23, 2024
A simpler version (makes use of spilling with general is pattern):
stringstr="a2";intx=1;inty=2;refintr=refstris"Hallo"?refx:refstris{Length:>=2 and <=10 or 22}?refy:refSystem.Runtime.CompilerServices.Unsafe.NullRef<int>();r++;r++;r++;intxxx=r;System.Console.WriteLine(xxx);//5System.Console.WriteLine(x);//1System.Console.WriteLine(y);//expected 5 - but we get 2
usingSystem;stringstr="a2";intx=1;inty=2;ref readonly varxx=refx;ref readonly intr=refEval(str,1)is"Hallo"?refxx:refEval(str,2)is{Length:>=2 and <=10 or 22}?refy:refSystem.Runtime.CompilerServices.Unsafe.NullRef<int>();refvarrx=refSystem.Runtime.CompilerServices.Unsafe.AsRef(inr);rx++;rx++;rx++;intxxx=r;System.Console.WriteLine(xxx);System.Console.WriteLine(x);System.Console.WriteLine(y);staticTEval<T>(Ts,inti){System.Console.WriteLine($"{s}{i}");returns;}
bernd5
changed the title
Bug: Conditional Expression stores ref result in non ref local temp (Only when SpillSequenceSpiller is used - e.g. for async/await)
Bug: Conditional Operator stores ref result in a non ref local temporary (Only when SpillSequenceSpiller is used - e.g. for async/await)
Jun 24, 2024
bernd5
changed the title
Bug: Conditional Operator stores ref result in a non ref local temporary (Only when SpillSequenceSpiller is used - e.g. for async/await)
Bug: Conditional Operator stores ref result in a non-ref-temporary (Only when SpillSequenceSpiller is used - e.g. for async/await)
Jun 24, 2024
Version Used: 847d588
Steps to Reproduce:
Compile and execute the following code:
Expected Behavior:
Same output for both methods (they are not really async)
Actual Behavior:
The result of the conditional expression is stored in a non-ref temp local which causes that the later increment operations do not change the original value - just the temp.
Error cause
The error is caused in SpillSequenceSpiller
The code should be:
But how can we determine if the result should be ref-readonly or not?
The text was updated successfully, but these errors were encountered: