Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use VisitRvalue to visit a function pointer #75996

Merged
merged 1 commit into from
Nov 21, 2024
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 @@ -3741,7 +3741,7 @@ public override BoundNode VisitReadOnlySpanFromArray(BoundReadOnlySpanFromArray

public override BoundNode VisitFunctionPointerInvocation(BoundFunctionPointerInvocation node)
{
Visit(node.InvokedExpression);
VisitRvalue(node.InvokedExpression);
VisitArguments(node.Arguments, node.ArgumentRefKindsOpt, node.FunctionPointer.Signature);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4152,5 +4152,54 @@ public unsafe void M(delegate*<void>? f) {
Diagnostic(ErrorCode.ERR_BadTypeArgument, "f").WithArguments("delegate*<void>").WithLocation(5, 43)
);
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75933")]
public void BoolLiteralInvocation_01()
{
var source = """
#nullable enable

class C
{
static unsafe void M()
{
int i = 0;
((delegate*<int, void>)true)(i);
}
}
""";

var comp = CreateCompilationWithFunctionPointers(source);
comp.VerifyEmitDiagnostics(
// (8,10): error CS0030: Cannot convert type 'bool' to 'delegate*<int, void>'
// ((delegate*<int, void>)true)(i);
Diagnostic(ErrorCode.ERR_NoExplicitConv, "(delegate*<int, void>)true").WithArguments("bool", "delegate*<int, void>").WithLocation(8, 10)
);
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75933")]
public void BoolLiteralInvocation_02()
{
var source = """
#nullable enable

using System;

class C
{
static unsafe void M()
{
var d = delegate (object? o, IntPtr f) { return ((delegate* managed<object?, long>)false)(o); };
}
}
""";

var comp = CreateCompilationWithFunctionPointers(source);
comp.VerifyEmitDiagnostics(
// (9,58): error CS0030: Cannot convert type 'bool' to 'delegate*<object?, long>'
// var d = delegate (object? o, IntPtr f) { return ((delegate* managed<object?, long>)false)(o); };
Diagnostic(ErrorCode.ERR_NoExplicitConv, "(delegate* managed<object?, long>)false").WithArguments("bool", "delegate*<object?, long>").WithLocation(9, 58)
);
}
}
}