Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
PR feedback
  • Loading branch information
cston committed Sep 17, 2022
commit 92f881b42f241fa3d62ec96da6d14839af34c67a
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ internal class SourceLocalSymbol : LocalSymbol
private readonly RefKind _refKind;
private readonly LocalDeclarationKind _declarationKind;
private readonly DeclarationScope _scope;
private readonly uint _localScopeDepth;

Copy link
Contributor

@AlekseyTs AlekseyTs Sep 16, 2022

Choose a reason for hiding this comment

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

It doesn't look like we need to store this value, we have _scopeBinder readily available #Closed

private TypeWithAnnotations.Boxed _type;

Expand Down Expand Up @@ -90,8 +89,6 @@ private SourceLocalSymbol(
// create this eagerly as it will always be needed for the EnsureSingleDefinition
_locations = ImmutableArray.Create<Location>(identifierToken.GetLocation());

_localScopeDepth = scopeBinder.LocalScopeDepth;

_refEscapeScope = this._refKind == RefKind.None ?
scopeBinder.LocalScopeDepth :
Binder.ExternalScope; // default to returnable, unless there is initializer
Expand Down Expand Up @@ -133,7 +130,7 @@ internal sealed override uint RefEscapeScope
return _refEscapeScope;
}
return _scope == DeclarationScope.RefScoped ?
_localScopeDepth :
_scopeBinder.LocalScopeDepth :
Binder.TopLevelScope;
}
}
Expand All @@ -148,7 +145,7 @@ internal sealed override uint ValEscapeScope
return _valEscapeScope;
}
return _scope == DeclarationScope.ValueScoped ?
_localScopeDepth :
_scopeBinder.LocalScopeDepth :
Binder.ExternalScope;
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9162,10 +9162,18 @@ static void Main()
scoped ref S r1 = ref s0;
r0 = ref r1; // 1
}
{
ref S r2 = ref s0;
r0 = ref r2;
}
{
scoped ref S r2 = ref r0;
r0 = ref r2; // 2
}
{
ref S r4 = ref r0;
r0 = ref r4;
}
}
}
ref struct S { }
Expand All @@ -9175,9 +9183,9 @@ ref struct S { }
// (9,13): error CS8374: Cannot ref-assign 'r1' to 'r0' because 'r1' has a narrower escape scope than 'r0'.
// r0 = ref r1; // 1
Diagnostic(ErrorCode.ERR_RefAssignNarrower, "r0 = ref r1").WithArguments("r0", "r1").WithLocation(9, 13),
// (13,13): error CS8374: Cannot ref-assign 'r2' to 'r0' because 'r2' has a narrower escape scope than 'r0'.
// (17,13): error CS8374: Cannot ref-assign 'r2' to 'r0' because 'r2' has a narrower escape scope than 'r0'.
// r0 = ref r2; // 2
Diagnostic(ErrorCode.ERR_RefAssignNarrower, "r0 = ref r2").WithArguments("r0", "r2").WithLocation(13, 13));
Diagnostic(ErrorCode.ERR_RefAssignNarrower, "r0 = ref r2").WithArguments("r0", "r2").WithLocation(17, 13));
}

[Fact]
Expand All @@ -9199,6 +9207,10 @@ static void Main()
scoped S s2 = s0;
s0 = s2; // 2
}
{
S s2 = s0;
s0 = s2;
}
}
}
ref struct S
Expand Down