Skip to content

Implement Static abstract members in interfaces #224

@MishaProductions

Description

@MishaProductions

Currently, when compiling the following code using master branch:

using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
using System.Runtime.Versioning;

namespace net8test
{
    public class Kernel: Sys.Kernel
    {
        [RequiresPreviewFeatures]
        protected override void BeforeRun()
        {
            var test = new Test();
            Test.InvokeBreakIl2cpu();
        }
        
        protected override void Run()
        {
            Console.Write("Input: ");
            var input = Console.ReadLine();
            Console.Write("Text typed: ");
            Console.WriteLine(input);
        }
    }


    public interface ITest<T>
    {
        [RequiresPreviewFeatures]
        public static abstract bool DoThings<TOther>(TOther value);
    }

    public class Test : ITest<object>
    {
        [RequiresPreviewFeatures]
        static bool ITest<object>.DoThings<TOther>(TOther t)
        {
            return true;
        }
        [RequiresPreviewFeatures]
        public static void BreakIl2cpu<TImplementation, TOther>() where TImplementation : ITest<object>
        {
             TImplementation.DoThings<Test>(new Test());
        }
         [RequiresPreviewFeatures]
        public static void InvokeBreakIl2cpu()
        {
            BreakIl2cpu<Test, object>();
        }
    }
}

Will result in the DoThings method not being emitted:

bin/cosmos/Debug/net6.0/net8test.asm:119142: error: undefined symbol `A0SystemBooleanA9A9net8testITest1A0SystemObjectDoThingsA9net8testTestA9net8testTest' (first use)
bin/cosmos/Debug/net6.0/net8test.asm:119142: error:  (Each undefined symbol is reported only once.)

Add the following to your csproj to reproduce the issue:

<EnablePreviewFeatures>true</EnablePreviewFeatures>
<LangVersion>11</LangVersion>

This issue blocks .NET 8 support as types such as UInt32 rely on this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions