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

Regression in stackalloc array of ref struct (dotnet core 3 preview 3) #33945

Closed
dlech opened this Issue Mar 7, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@dlech
Copy link

dlech commented Mar 7, 2019

This sample code builds successfully in dotnet core 3 preview 2 and earlier (including dotent core 2.x) but fails in dotnet core 3 preview 3

test.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>8.0</LangVersion>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  </PropertyGroup>

</Project>

Class1.cs

using System;
using System.Runtime.InteropServices;

namespace test
{
    ref struct S
    {
    }

    public class Class1
    {
        public unsafe void M()
        {
            var x = stackalloc S[10];
        }
    }
}

dotnet core 3 preview 2

$ dotnet build
Microsoft (R) Build Engine version 16.0.385-preview+g966cdf2ac6 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for /home/david/tmp/test/test.csproj...
  Restore completed in 115.53 ms for /home/david/tmp/test/test.csproj.
/home/david/bin/dotnet2/sdk/3.0.100-preview-010184/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(151,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview [/home/david/tmp/test/test.csproj]
  test -> /home/david/tmp/test/bin/Debug/netstandard2.0/test.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.22

dotnet core 3 preview 3

$ dotnet build
Microsoft (R) Build Engine version 16.0.443+g5775d0d6bb for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Persisting no-op dg to /home/david/tmp/test/obj/test.csproj.nuget.dgspec.json
  Restore completed in 127.26 ms for /home/david/tmp/test/test.csproj.
/home/david/bin/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(151,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview [/home/david/tmp/test/test.csproj]
Class1.cs(14,32): error CS0611: Array elements cannot be of type 'S' [/home/david/tmp/test/test.csproj]

Build FAILED.

Class1.cs(14,32): error CS0611: Array elements cannot be of type 'S' [/home/david/tmp/test/test.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.21

Perhaps this is an unintended side effect of 0bee025#diff-ef3f78219358a0705f76762ce80bb8c8?

@jcouv

This comment has been minimized.

Copy link
Member

jcouv commented Mar 7, 2019

@dlech Thanks for reporting this. Could you add #error version to your code and share the resulting error message in both environments? I'm trying to confirm when this break was introduced (in terms of compiler versions).

Never mind, I found the source of the change. Thanks

@jcouv

This comment has been minimized.

Copy link
Member

jcouv commented Mar 7, 2019

I suspect the regression came in 16.0p3 in #32431

BindStackAllocArrayCreationExpression used to call BindType, but now it calls BindArrayType which additionally checks IsRestrictedType.

Tagging @gafter

@jcouv

This comment has been minimized.

Copy link
Member

jcouv commented Mar 15, 2019

Fixed in dev16 (rc4)

@jcouv jcouv closed this Mar 15, 2019

@jcouv

This comment has been minimized.

Copy link
Member

jcouv commented Mar 15, 2019

Thanks @dlech for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
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.