Skip to content

Commit

Permalink
Avoid cycle caused by calculation of ObsoleteState/ExperimentalState. (
Browse files Browse the repository at this point in the history
…dotnet#70171)

* Avoid cycle caused by calculation of ObsoleteState/ExperimentalState.

Fixes dotnet#70007.

* Add C# test

* More tests
  • Loading branch information
AlekseyTs authored Oct 11, 2023
1 parent 6d59156 commit d49b29e
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/Compilers/CSharp/Test/Semantic/Semantics/BindingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3907,5 +3907,27 @@ void N()
var typeInfo = model.GetTypeInfo(lambda.Body);
Assert.Equal("System.Int32", typeInfo.Type.ToTestDisplayString());
}

[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/70007")]
public void CycleThroughAttribute()
{
var compilation = CreateCompilation(@"
using System.Reflection;
[assembly: AssemblyVersion(MainVersion.CurrentVersion)]
public class MainVersion
{
public const string Hauptversion = ""8"";
public const string Nebenversion = ""2"";
public const string Build = ""0"";
public const string Revision = ""1"";
public const string CurrentVersion = Hauptversion + ""."" + Nebenversion + ""."" + Build + ""."" + Revision;
}
");
CompileAndVerify(compilation).VerifyDiagnostics();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End If

Dim boundInitValueHasErrorsOrConstTypeIsWrong As Boolean =
initValueDiagnostics.HasAnyErrors OrElse fieldSymbol.HasDeclaredType AndAlso Not targetType.IsValidTypeForConstField()
initValueDiagnostics.HasAnyResolvedErrors OrElse fieldSymbol.HasDeclaredType AndAlso Not targetType.IsValidTypeForConstField()

' NOTE: we'll only report ERR_RequiredConstConversion2 ("Conversion from '...' to '.' cannot occur in
' NOTE: a constant expression") and ERR_RequiredConstExpr ("Constant expression is required") in case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3446,5 +3446,121 @@ End Class </file>

CompileAndVerify(compilation, expectedOutput:="42")
End Sub

<WorkItem("https://github.com/dotnet/roslyn/issues/70007")>
<Fact()>
Public Sub CycleThroughAttribute_01()
Dim compilation = CreateCompilation(
<compilation>
<file name="a.vb"><![CDATA[
Imports System.Reflection

<Assembly: AssemblyVersion(MainVersion.CurrentVersion)>

Public Class MainVersion
Public Const Hauptversion As String = "8"
Public Const Nebenversion As String = "2"
Public Const Build As String = "0"
Public Const Revision As String = "1"

Public Const CurrentVersion As String = Hauptversion & "." & Nebenversion & "." & Build & "." & Revision
End Class
]]></file>
</compilation>)

CompileAndVerify(compilation).VerifyDiagnostics()
End Sub

<WorkItem("https://github.com/dotnet/roslyn/issues/70007")>
<Fact()>
Public Sub CycleThroughAttribute_02()
Dim compilation = CreateCompilation(
<compilation>
<file name="a.vb"><![CDATA[
<Module: MyAttribute(MainVersion.CurrentVersion)>

Public Class MainVersion
Public Const Hauptversion As String = "8"
Public Const Nebenversion As String = "2"
Public Const Build As String = "0"
Public Const Revision As String = "1"

Public Const CurrentVersion As String = Hauptversion & "." & Nebenversion & "." & Build & "." & Revision
End Class

class MyAttribute
Inherits System.Attribute

Sub New(x as String)
End Sub
End Class
]]></file>
</compilation>)

CompileAndVerify(compilation).VerifyDiagnostics()
End Sub

<WorkItem("https://github.com/dotnet/roslyn/issues/70007")>
<Fact()>
Public Sub CycleThroughAttribute_03()
Dim compilation = CreateCompilation(
<compilation>
<file name="a.vb"><![CDATA[
<MyAttribute(MainVersion.CurrentVersion)>
Public Class MainVersion
Public Const Hauptversion As String = "8"
Public Const Nebenversion As String = "2"
Public Const Build As String = "0"
Public Const Revision As String = "1"

Public Const CurrentVersion As String = Hauptversion & "." & Nebenversion & "." & Build & "." & Revision
End Class

class MyAttribute
Inherits System.Attribute

Sub New(x as String)
End Sub
End Class
]]></file>
</compilation>)

CompileAndVerify(compilation).VerifyDiagnostics()
End Sub

<WorkItem("https://github.com/dotnet/roslyn/issues/70007")>
<Fact()>
Public Sub CycleThroughAttribute_04()
Dim compilation = CreateCompilation(
<compilation>
<file name="a.vb"><![CDATA[
Imports System.Reflection

<Assembly: AssemblyVersion(MainVersion.CurrentVersion)>

<Module: MyAttribute(MainVersion.CurrentVersion)>

<MyAttribute(MainVersion.CurrentVersion)>
Public Class MainVersion
Public Const Hauptversion As String = "8"
Public Const Nebenversion As String = "2"
Public Const Build As String = "0"
Public Const Revision As String = "1"

Public Const CurrentVersion As String = Hauptversion & "." & Nebenversion & "." & Build & "." & Revision
End Class

class MyAttribute
Inherits System.Attribute

Sub New(x as String)
End Sub
End Class
]]></file>
</compilation>)

CompileAndVerify(compilation).VerifyDiagnostics()
End Sub

End Class
End Namespace

0 comments on commit d49b29e

Please sign in to comment.