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

Allow usage of ref structs in VB despite CompilerFeatureRequired #65431

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE
Private Function DeriveCompilerFeatureRequiredDiagnostic() As DiagnosticInfo
Dim decoder = New MetadataDecoder(ContainingPEModule, Me)

Dim diagnostic = DeriveCompilerFeatureRequiredAttributeDiagnostic(Me, ContainingPEModule, Handle, CompilerFeatureRequiredFeatures.None, decoder)
Dim diagnostic = DeriveCompilerFeatureRequiredAttributeDiagnostic(Me, ContainingPEModule, Handle, CompilerFeatureRequiredFeatures.RefStructs, decoder)

If diagnostic IsNot Nothing Then
Return diagnostic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ProjectReference Include="..\..\..\Test\Resources\Core\Microsoft.CodeAnalysis.Compiler.Test.Resources.csproj" />
<ProjectReference Include="..\..\..\Test\Utilities\VisualBasic\Microsoft.CodeAnalysis.VisualBasic.Test.Utilities.vbproj" />
<ProjectReference Include="..\..\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" />
<PackageReference Include="Basic.Reference.Assemblies.Net60" Version="$(BasicReferenceAssembliesNet60Version)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="$(SystemDrawingCommonVersion)" Condition="$(TargetFramework) == 'net7.0'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests
''' <summary>
''' Ref field in ref struct.
''' </summary>
<Fact>
<Fact, WorkItem(65392, "https://github.com/dotnet/roslyn/issues/65392")>
Public Sub RefField_01()
Dim sourceA =
"public ref struct S<T>
Expand All @@ -42,9 +42,6 @@ End Module"
BC30668: 'S(Of Integer)' is obsolete: 'Types with embedded references are not supported in this version of your compiler.'.
Dim s = New S(Of Integer)()
~~~~~~~~~~~~~
BC37319: 'S(Of T)' requires compiler feature 'RefStructs', which is not supported by this version of the Visual Basic compiler.
Dim s = New S(Of Integer)()
~~~~~~~~~~~~~
BC30656: Field 'F' is of an unsupported type.
Console.WriteLine(s.F)
~~~
Expand All @@ -56,6 +53,33 @@ BC30656: Field 'F' is of an unsupported type.
Assert.True(field.HasUnsupportedMetadata)
End Sub

<Fact, WorkItem(65392, "https://github.com/dotnet/roslyn/issues/65392")>
Public Sub CanUsePassThroughRefStructInstances()
Dim source =
"Imports System
Module Program
Sub Main()
Dim s = ""123"".AsSpan()
Dim s2 As ReadOnlySpan(Of Char) = ""123"".AsSpan()
Dim s3 = MemoryExtensions.AsSpan(""123"")
End Sub
End Module"

Dim comp = CreateCompilation(source, targetFramework:=TargetFramework.Net60)
comp.AssertTheseDiagnostics(<expected>
BC30668: 'ReadOnlySpan(Of Char)' is obsolete: 'Types with embedded references are not supported in this version of your compiler.'.
Dim s2 As ReadOnlySpan(Of Char) = "123".AsSpan()
~~~~~~~~~~~~~~~~~~~~~
</expected>)

comp = CreateCompilation(source, targetFramework:=TargetFramework.Net70)
comp.AssertTheseDiagnostics(<expected>
BC30668: 'ReadOnlySpan(Of Char)' is obsolete: 'Types with embedded references are not supported in this version of your compiler.'.
Dim s2 As ReadOnlySpan(Of Char) = "123".AsSpan()
~~~~~~~~~~~~~~~~~~~~~
</expected>)
End Sub

''' <summary>
''' Ref field in class.
''' </summary>
Expand Down