Skip to content

Disallow __arglist in local functions#16660

Merged
agocke merged 2 commits intodotnet:masterfrom
agocke:disable-arglist-in-local-functions
Jan 25, 2017
Merged

Disallow __arglist in local functions#16660
agocke merged 2 commits intodotnet:masterfrom
agocke:disable-arglist-in-local-functions

Conversation

@agocke
Copy link
Member

@agocke agocke commented Jan 20, 2017

Customer scenario

Currently declaring a local function with an __arglist parameter is not illegal, but it should be.
Disallowing this later is a breaking change.

Bugs this fixes:

Fixes #10765

Workarounds, if any

None.

Risk

This is a very small change that's specific to local functions. The change is well understood -- it is the same as the check done in lambdas. This change also only prohibits functionality.

Performance impact

None.

Is this a regression from a previous update?

No.

Root cause analysis:

New feature

How was the bug found?

Customer reported.

@agocke
Copy link
Member Author

agocke commented Jan 20, 2017

@dotnet/roslyn-compiler For review

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM

{
if (p.IsArgList)
{
diagnostics.Add(ErrorCode.ERR_IllegalVarArgs, p.Location);
Copy link
Contributor

Choose a reason for hiding this comment

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

diagnostics.Add(ErrorCode.ERR_IllegalVarArgs, p.Location); [](start = 20, length = 58)

It feels like this check belongs in GrabDiagnostics/GetDeclarationDiagnostics on the local function symbol.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was going to eagerly report diagnostics that don't have any risk of cycles and only put lazy things into GetDeclarationDiagnostics. Would you prefer that everything be reported in GetDeclarationDiagnostics if feasible?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should follow approach when diagnostics about declaration is produced by symbols.

Diagnostic(ErrorCode.ERR_IllegalVarArgs, "__arglist").WithLocation(24, 20),
// (26,31): error CS0190: The __arglist construct is valid only within a variable argument method
// Console.WriteLine(__arglist);
Diagnostic(ErrorCode.ERR_ArgsInvalid, "__arglist").WithLocation(26, 31),
Copy link
Contributor

Choose a reason for hiding this comment

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

This error feels unexpected, it looks like Binder.BindArgList skips through local functions, but it probably shouldn't.

Copy link
Member Author

Choose a reason for hiding this comment

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

@AlekseyTs This seems weird for lambdas too... I don't think we should care if the containing member is/is not __arglist if we're inside a lambda/local function while using __arglist. It's invalid no matter what.

I've filed #16720 to rationalize this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is what the logic is about in the place where ERR_ArgsInvalid is reported. Try to add __arglist to the parameter list of the containing function and see if that makes any difference.

@AlekseyTs
Copy link
Contributor

Is there a reason to disallow __arglist in local functions from the language design point of view? It looks like a simple change in Binder.BindArgList might enable the feature.

@jaredpar
Copy link
Member

@AlekseyTs the design called for it to be disallowed, mostly because we didn't have a good use case for it. Should keep it disabled at this point as enabling it won't meet the bar.

@AlekseyTs
Copy link
Contributor

enabling it won't meet the bar.

Makes sense.

@agocke
Copy link
Member Author

agocke commented Jan 24, 2017

test windows_release_unit64_prtest please

@agocke
Copy link
Member Author

agocke commented Jan 24, 2017

@MattGertz For escrow approval

@natidea
Copy link
Contributor

natidea commented Jan 25, 2017

Approved to merge via 369813

@agocke agocke merged commit 27f69fd into dotnet:master Jan 25, 2017
@agocke agocke deleted the disable-arglist-in-local-functions branch September 12, 2018 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block __arglist in local functions

7 participants