Skip to content

When forced into spilling a byref method VB compiler asserts. Should it be an error? #24275

@VSadov

Description

@VSadov

Testcase: SpillingByrefCall_Spilling

C# class introduces ref methods

using System;

public class TestClass
{
    int x = 0;

    public ref int Save(int y)
    {
        x = y;
        return ref x;
    }

    public void Write(ref int y)
    {
        Console.WriteLine(y);
    }

    public void Write(ref int y, int z)
    {
        Console.WriteLine(y);
    }
}

VB test code (references the above code):

Imports System.Threading.Tasks

Module Module1

    Sub Main()
        TestMethod().Wait()
    End Sub

    Async Function TestMethod() As Task
        Dim inst = New TestClass

        ' ERROR?
        ' currently `ref` is spilled 'by-value' and assert fires.
        inst.Write(inst.Save(Await Task.FromResult(30)), inst.Save(Await Task.FromResult(33)))
    End Function

End Module

Expected:

  • not sure. C# gives an error. Possibly VB should as well

Actual:

  • compiler asserts. If ignored, the ref argument is spilled by-value

It might actually be ok in VB to spill by-value. Not sure.
In any case there should not be asserts.

Also note - changing current behavior (ignoring the assert) might be a compat concern. This behavior existed since the last release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions