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

Do not resolve diagnostics early during attribute binding #71140

Merged
merged 10 commits into from
Dec 15, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Dim displayName As String = TryCast(attrData.CommonConstructorArguments(0).ValueInternal, String)

If displayName Is Nothing Then
diagnostics.Add(ERRID.ERR_FriendAssemblyNameInvalid, If(nodeOpt IsNot Nothing, nodeOpt.GetLocation(), NoLocation.Singleton), displayName)
diagnostics.Add(ERRID.ERR_FriendAssemblyNameInvalid, If(nodeOpt IsNot Nothing, nodeOpt.GetLocation(), NoLocation.Singleton), "")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change wasn't a cycle, we just clearly didn't have any tests covering it, as it is guaranteed to hit a Debug.Assert.

Return False
End If

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2701,6 +2701,59 @@ End Class
CompileAndVerify(compilation, expectedOutput:="42")
End Sub

<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/71039")>
Public Sub ConstInAttributes_NoCycle_01()
Dim source = "
Imports ILGPU
Imports System.Runtime.CompilerServices

<Assembly: InternalsVisibleTo(Context.RuntimeAssemblyName)>

Namespace ILGPU
Public Class Context
Public Const RuntimeAssemblyName As String = RuntimeSystem.AssemblyName
Public Property RuntimeSystem As RuntimeSystem
End Class
End Namespace
"

CreateCompilation(source).AssertTheseDiagnostics(<expected><![CDATA[
BC31537: Friend declaration '' is invalid and cannot be resolved.
<Assembly: InternalsVisibleTo(Context.RuntimeAssemblyName)>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC30369: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
Public Const RuntimeAssemblyName As String = RuntimeSystem.AssemblyName
~~~~~~~~~~~~~
BC30002: Type 'RuntimeSystem' is not defined.
Public Property RuntimeSystem As RuntimeSystem
~~~~~~~~~~~~~]]></expected>
)
End Sub

<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/71039")>
Public Sub ConstInAttributes_NoCycle_02()
Dim source = "
Imports ILGPU
Imports System.Runtime.CompilerServices

<Assembly: InternalsVisibleTo(Context.RuntimeAssemblyName)>

Namespace ILGPU
Public Class Context
Public Const RuntimeAssemblyName As String = RuntimeSystem.AssemblyName
Public Property RuntimeSystem As RuntimeSystem
End Class

Public Class RuntimeSystem
Public Const AssemblyName As String = ""RuntimeSystem""
End Class
End Namespace
"

Dim compilation = CreateCompilation(source)
CompileAndVerify(compilation)
End Sub

<WorkItem(1108036, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1108036")>
<Fact()>
Public Sub Bug1108036()
Expand Down