Skip to content

Commit

Permalink
Add regression test for attribute with async delegate parameter (#30969)
Browse files Browse the repository at this point in the history
* Add regression test for attribute consuming async Task-returning delegate

* Add corresponding VB test
  • Loading branch information
RikkiGibson authored Nov 6, 2018
1 parent 2468ad7 commit 1abe965
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8913,6 +8913,44 @@ internal sealed class CSharpCompilerDiagnosticAnalyzer
);
}

[Fact, WorkItem(30833, "https://github.com/dotnet/roslyn/issues/30833")]
public void AttributeWithTaskDelegateParameter()
{
string code = @"
using System;
using System.Threading.Tasks;
namespace a
{
class Class1
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
class CommandAttribute : Attribute
{
public delegate Task FxCommand();
public CommandAttribute(FxCommand Fx)
{
this.Fx = Fx;
}
public FxCommand Fx { get; set; }
}
[Command(UserInfo)]
public static async Task UserInfo()
{
await Task.CompletedTask;
}
}
}
";
CreateCompilationWithMscorlib46(code).VerifyDiagnostics(
// (22,4): error CS0181: Attribute constructor parameter 'Fx' has type 'Class1.CommandAttribute.FxCommand', which is not a valid attribute parameter type
// [Command(UserInfo)]
Diagnostic(ErrorCode.ERR_BadAttributeParamType, "Command").WithArguments("Fx", "a.Class1.CommandAttribute.FxCommand").WithLocation(22, 4));
}

#endregion
}
}
34 changes: 34 additions & 0 deletions src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -4618,5 +4618,39 @@ End Class
Assert.NotNull(compilation2.GetTypeByMetadataName("TestReference2"))
End Sub

<Fact>
Public Sub AttributeWithTaskDelegateParameter()
Dim code = "
Imports System
Imports System.Threading.Tasks

Namespace a
Public Class Class1
<AttributeUsage(AttributeTargets.Class, AllowMultiple:=True)>
Public Class CommandAttribute
Inherits Attribute

Public Delegate Function FxCommand() As Task

Public Sub New(Fx As FxCommand)
Me.Fx = Fx
End Sub

Public Property Fx As FxCommand
End Class

<Command(AddressOf UserInfo)>
Public Shared Async Function UserInfo() As Task
Await New Task(
Sub()
End Sub)
End Function
End Class
End Namespace
"
CreateCompilationWithMscorlib45(code).VerifyDiagnostics(
Diagnostic(ERRID.ERR_BadAttributeConstructor1, "Command").WithArguments("a.Class1.CommandAttribute.FxCommand").WithLocation(20, 10),
Diagnostic(ERRID.ERR_RequiredConstExpr, "AddressOf UserInfo").WithLocation(20, 18))
End Sub
End Class
End Namespace

0 comments on commit 1abe965

Please sign in to comment.