Giter Site home page Giter Site logo

Bug: Conditional Operator stores ref result in a non-ref-temporary (Only when SpillSequenceSpiller is used - e.g. for async/await) about roslyn HOT 2 OPEN

bernd5 avatar bernd5 commented on July 23, 2024
Bug: Conditional Operator stores ref result in a non-ref-temporary (Only when SpillSequenceSpiller is used - e.g. for async/await)

from roslyn.

Comments (2)

bernd5 avatar bernd5 commented on July 23, 2024

A simpler version (makes use of spilling with general is pattern):

string str = "a2";
int x = 1;
int y = 2;

ref int r =
      ref str is "Hallo" ? ref x
    : ref str is { Length: >= 2 and <= 10 or 22 } ? ref y
    : ref System.Runtime.CompilerServices.Unsafe.NullRef<int>();

r++;
r++;
r++;
int xxx = r;
System.Console.WriteLine(xxx); //5
System.Console.WriteLine(x); //1
System.Console.WriteLine(y); //expected 5 - but we get 2

from roslyn.

bernd5 avatar bernd5 commented on July 23, 2024

And a version with ref readonly:

using System;


string str = "a2";
int x = 1;
int y = 2;

ref readonly var xx = ref x; 

ref readonly int r =
      ref Eval(str, 1) is "Hallo" ? ref xx
    : ref Eval(str, 2) is { Length: >= 2 and <= 10 or 22 } ? ref y
    : ref System.Runtime.CompilerServices.Unsafe.NullRef<int>();

ref var rx = ref System.Runtime.CompilerServices.Unsafe.AsRef(in r);

rx++;
rx++;
rx++;
int xxx = r;
System.Console.WriteLine(xxx);
System.Console.WriteLine(x);
System.Console.WriteLine(y);


static T Eval<T>(T s, int i)
{
    System.Console.WriteLine($"{s} {i}");
    return s;
}

from roslyn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.