-
Notifications
You must be signed in to change notification settings - Fork 231
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
TokenType: Tests and support for scoped type declarations #8061
Changes from all commits
b42a65e
f6ec351
fec1567
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1286,4 +1286,47 @@ public void M(object o) | |
} | ||
} | ||
""", allowSemanticModel); | ||
|
||
[DataTestMethod] | ||
[DataRow("[k:scoped] ref S s2 = ref s1;", false)] | ||
[DataRow("scoped ref [t:S] s2 = ref s1;", false)] | ||
[DataRow("ref [t:S] s2 = ref s1;", false)] | ||
[DataRow("scoped [t:S] s2 = s1;", false)] | ||
[DataRow("[k:scoped] [k:ref] [k:readonly] [t:S] [u:s2] = [k:ref] [u:s1];", false)] | ||
[DataRow("[k:int] [u:scoped] = 1;", false)] | ||
public void IdentifierToken_Scoped_Local(string localDeclaration, bool allowSemanticModel) => | ||
ClassifierTestHarness.AssertTokenTypes($$""" | ||
using System; | ||
|
||
public ref struct S { } | ||
|
||
public class C | ||
{ | ||
public void M(ref S s1) | ||
{ | ||
{{localDeclaration}} | ||
} | ||
} | ||
""", allowSemanticModel); | ||
|
||
[DataTestMethod] | ||
[DataRow("[k:scoped] ref S s", false)] | ||
[DataRow("scoped ref [t:S] s", false)] | ||
[DataRow("ref [t:S] s", false)] | ||
[DataRow("scoped [t:S] s", false)] | ||
[DataRow("[k:scoped] [k:ref] [t:S] [u:s]", false)] | ||
[DataRow("[k:int] [u:scoped]", false)] | ||
public void IdentifierToken_Scoped_Parameter(string parameterDeclaration, bool allowSemanticModel) => | ||
ClassifierTestHarness.AssertTokenTypes($$""" | ||
using System; | ||
|
||
public ref struct S { } | ||
|
||
public class C | ||
{ | ||
public void M({{parameterDeclaration}}) | ||
{ | ||
} | ||
} | ||
""", allowSemanticModel); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: I would also add tests with a parameter and/or variable named int scoped = 3; I think it would make sense to assert that |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: We could add a test combining
scoped ref
withreadonly
, when the reference is one to areadonly ref struct
, just to make sure thatreadonly
is interpreted as keyword, when following ref.E.g. here, where GitHub fails at properly coloring it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not compile (readonly parameter are at implemented proposal stage dotnet/csharplang#6010 for C#12). But for locals it works and I added a test case.