-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix parsing of generics in casts. #69519
Changes from all commits
e3c972a
f740a66
547de9c
054b157
370627d
c7f5197
d4ac003
9bd7a2a
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 |
---|---|---|
|
@@ -5824,7 +5824,7 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( | |
// Note: we check if we got 'MustBeType' which triggers for predefined types, | ||
// (int, string, etc.), or array types (Goo[], A<T>[][] etc.), or pointer types | ||
// of things that must be types (int*, void**, etc.). | ||
isDefinitelyTypeArgumentList = DetermineIfDefinitelyTypeArgumentList(isDefinitelyTypeArgumentList); | ||
isDefinitelyTypeArgumentList = isDefinitelyTypeArgumentList || this.CurrentToken.Kind is SyntaxKind.CommaToken or SyntaxKind.GreaterThanToken; | ||
result = ScanTypeFlags.GenericTypeOrMethod; | ||
break; | ||
|
||
|
@@ -5850,8 +5850,8 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( | |
// } | ||
|
||
case ScanTypeFlags.NullableType: | ||
// See above. If we have X<Y?, or X<Y?>, then this is definitely a type argument list. | ||
isDefinitelyTypeArgumentList = DetermineIfDefinitelyTypeArgumentList(isDefinitelyTypeArgumentList); | ||
// See above. If we have `X<Y?,` or `X<Y?>` then this is definitely a type argument list. | ||
isDefinitelyTypeArgumentList = isDefinitelyTypeArgumentList || this.CurrentToken.Kind is SyntaxKind.CommaToken or SyntaxKind.GreaterThanToken; | ||
if (isDefinitelyTypeArgumentList) | ||
{ | ||
result = ScanTypeFlags.GenericTypeOrMethod; | ||
|
@@ -5900,17 +5900,15 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( | |
} | ||
|
||
greaterThanToken = this.EatToken(); | ||
return result; | ||
} | ||
|
||
private bool DetermineIfDefinitelyTypeArgumentList(bool isDefinitelyTypeArgumentList) | ||
{ | ||
if (!isDefinitelyTypeArgumentList) | ||
// If we have `X<Y>)` then this would definitely be a type argument list. | ||
isDefinitelyTypeArgumentList = isDefinitelyTypeArgumentList || this.CurrentToken.Kind is SyntaxKind.CloseParenToken; | ||
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. Could you help me understand in which scenarios we are depending on this line versus line 5874 for correct behavior? 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. so 5874 related to incomplete nested generics. so if you had This line applies when you have 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. thanks! |
||
if (isDefinitelyTypeArgumentList) | ||
{ | ||
isDefinitelyTypeArgumentList = this.CurrentToken.Kind is SyntaxKind.CommaToken or SyntaxKind.GreaterThanToken; | ||
result = ScanTypeFlags.GenericTypeOrMethod; | ||
} | ||
|
||
return isDefinitelyTypeArgumentList; | ||
return result; | ||
} | ||
|
||
// ParseInstantiation: Parses the generic argument/parameter parts of the name. | ||
|
@@ -11798,7 +11796,7 @@ private bool ScanCast(bool forPattern = false) | |
|
||
this.EatToken(); | ||
|
||
var type = this.ScanType(forPattern: forPattern); | ||
var type = this.ScanType(forPattern); | ||
if (type == ScanTypeFlags.NotType) | ||
{ | ||
return false; | ||
|
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.
i inlined this method as i found it easier to reason about just looking at teh check directly in code.
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.
note: tehre are further changes i'd like to make to this method for clarity/correctness/invariants. but i'm trying to keep the PR small for the purposes of fixing this important issue.