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

error CS8374: Cannot ref-assign 'x!' to 'x' because 'x!' has a narrower escape scope than 'x'. #31297

Closed
TessenR opened this issue Nov 21, 2018 · 1 comment
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug New Language Feature - Nullable Reference Types Nullable Reference Types
Milestone

Comments

@TessenR
Copy link

TessenR commented Nov 21, 2018

Version Used:

Branch C# 8.0: Nullable reference type (29 Oct 2018)
https://github.com/dotnet/csharplang/blob/master/proposals/nullable-reference-types.md
Latest commit 2f8fef by AlekseyTs:
Compare Nullable modifiers while comparing type symbols by default. (#30770)

Steps to Reproduce:

class C
{
    void M()
    {
        ref var x = ref NullableRef();
        x = ref x!;
        
        // interestingly enough this one works
        ref var y = ref NullableRef()!;
        y = ref y!;
    }
    
    extern ref string? NullableRef();
}

https://sharplab.io/#v2:EYLgZgpghgLgrgJwgZwLQDk4BstWFiAJQkiQDsBjCAFQE8AHFAHwAEAmAAgGEBYAKADe/DiI4sALBwCyACgCUw0UL6jVHJGA4A3KAg4APDgF51JDphx4CxMPIDcitQeOnN+gIQOVTjo7UB6fw4ASzIYCCRkGFCAcyxaDggyAHs4GIALDhh04OQOZLIIDgB3ZIQAa2Q/VQ1tXQ4Ek1qLXHwiEnlPatFG1wau7xEAXz8/CH1whDI+lgBGAAYAfnNsVusOuS8hoA===

Expected Behavior:

No errors

Actual Behavior:

error CS8374: Cannot ref-assign 'x!' to 'x' because 'x!' has a narrower escape scope than 'x'.


[jcouv update:] I've tagged some code with this issue (CheckValueKind, GetValEscape, CheckValEscape). Please search for them when resolving this issue.

@jaredpar
Copy link
Member

jaredpar commented Jan 2, 2019

Wow, nice find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug New Language Feature - Nullable Reference Types Nullable Reference Types
Projects
None yet
Development

No branches or pull requests

3 participants