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

"ref readonly" local functions should be treated as "ref readonly" #18419

Merged
merged 2 commits into from
Apr 5, 2017

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented Apr 4, 2017

The code was ignoring "readonly" part for local functions,

Fixes:#18357

The code was ignoring "readonly" part for local functions,

Fixes:dotnet#18357
@VSadov
Copy link
Member Author

VSadov commented Apr 4, 2017

CC: @OmarTawfik

@VSadov
Copy link
Member Author

VSadov commented Apr 4, 2017

@dotnet/roslyn-compiler - please review

Copy link
Contributor

@OmarTawfik OmarTawfik left a comment

Choose a reason for hiding this comment

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

Can we also add another test for the negative case? (ref-ness mismatch between local/outer functions).
Is it another code path as well?

@@ -73,7 +73,7 @@ internal sealed class LocalFunctionSymbol : MethodSymbol
}

_binder = binder;
_refKind = (syntax.ReturnType.Kind() == SyntaxKind.RefType) ? RefKind.Ref : RefKind.None;
_syntax.ReturnType.SkipRef(out _refKind);
Copy link
Member

@agocke agocke Apr 4, 2017

Choose a reason for hiding this comment

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

Consider adding a helper to make this idiom clearer. "Skipping" the ref to get the RefKind is not very obvious. #Resolved

Copy link
Member

@agocke agocke Apr 4, 2017

Choose a reason for hiding this comment

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

Also consider removing this field entirely and just computing the RefKind based on syntax every time. I bet the time/memory trade off here is not useful. Same with SourceMemberMethodSymbol. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

we do not keep the syntax. we keep the reference, so it is not as trivial. I think I can make ref kind lazy for local functions.
Not so sure about MemberMethod though - getting return type is complicated there because of overriding. I'll keep it eager for MemberMethod.


In reply to: 109756907 [](ancestors = 109756907)

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

I agree with @OmarTawfik. I'd like to see a negative test case here as well.

@VSadov
Copy link
Member Author

VSadov commented Apr 5, 2017

@agocke - looks ok?

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

I meant that you could remove the refkind field and just have a property that computes the value every time. It seems trivial to calculate from the syntax and having an extra bool doesn't seem with it. But this is also fine and had the plus that all the calculation is in the same place. LGTM

@cston
Copy link
Member

cston commented Apr 5, 2017

LGTM

@VSadov VSadov merged commit 6dd756f into dotnet:features/readonly-ref Apr 5, 2017
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.

5 participants