Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify older compilers consuming newer library that uses the new constraints #35660

Closed
jcouv opened this issue May 11, 2019 · 3 comments
Closed
Assignees
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented May 11, 2019

Ported issue from #22152 (comment)

@jcouv jcouv added Area-Compilers Test Test failures in roslyn-CI New Language Feature - Nullable Reference Types Nullable Reference Types labels May 11, 2019
@jcouv jcouv added this to the 16.3 milestone Jul 11, 2019
@RikkiGibson
Copy link
Contributor

Does this refer specifically to the 'notnull' constraint? Or to other features as well?

@jcouv
Copy link
Member Author

jcouv commented Aug 14, 2019

class?, class (in a #nullable enable context) and notnull

@RikkiGibson RikkiGibson self-assigned this Aug 22, 2019
@RikkiGibson
Copy link
Contributor

I created a small project to manually test this. As expected, the project using Roslyn 2.x ignored the notnull constraint and interpreted the class constraints inside '#nullable enable' context the same as oblivious class constraints would be interpreted.

ClassLibrary

(using Roslyn 3.3.x compiler, LangVersion preview, targeting netstandard2.0)

public class Class1<T> where T : notnull
{
    public void M(T t) { }
}

public class Class2<T> where T : class
{
    public void M(T t) { }
}

public class Class3<T> where T : class?
{
    public void M(T t) { }
}

public class Class4
{
    public static void M1<T>(T t) where T : notnull { }
    public static void M2<T>(T t) where T : class { }
    public static void M3<T>(T t) where T : class? { }
}

ConsoleApp

(using Roslyn 2.10.x compiler, default LangVersion, targeting netcoreapp2.2)

class Program
{
    static void Main(string[] args)
    {
        new Class1<string>().M(null);
        new Class1<string>().M("a");

        new Class1<int?>().M(null);
        new Class1<int?>().M(42);
        new Class1<int>().M(42);

        new Class2<string>().M(null);
        new Class2<string>().M("a");

        new Class3<string>().M(null);
        new Class3<string>().M("a");

        Class4.M1((string)null);
        Class4.M1("a");

        Class4.M2((string)null);
        Class4.M2("a");

        Class4.M3((string)null);
        Class4.M3("a");

        // the non-nullable 'class' and 'class?' constraint
        // is correctly seen as just a class constraint
        // new Class2<int>();
        // new Class3<int>();
        // Class4.M2(42);
        // Class4.M3(42);

        Console.WriteLine("done");
        Console.ReadKey();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants