-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Nullable annotation is no longer part of array rank specifier #32431
Conversation
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests4.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests4.cs
Outdated
Show resolved
Hide resolved
Fixes dotnet#32290 and other related issues
What is the point of adding Anyway, thanks for the feedback. #Closed |
5920353
to
c4d2ef2
Compare
In my experience, PRs marked as "personal" get reviewed the fastest. There may be some yet-to-be-named law for that ;-) #Closed |
…d into semantic analysis - Move error checking for invalid array dimensions out of the parser and into semantic analysis - Diagnose `e is string?` Fixes dotnet#32025
@@ -5037,6 +5037,12 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ | |||
<data name="ERR_PatternNullableType" xml:space="preserve"> | |||
<value>It is not legal to use nullable type '{0}' in a pattern; use the underlying type '{1}' instead.</value> | |||
</data> | |||
<data name="ERR_IsNullableType" xml:space="preserve"> | |||
<value>It is not legal to use nullable type '{0}?' in an is-type expression; use the underlying type '{0}' instead.</value> |
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 would add "because is
never matches null
" to make it clear why it's illegal. I suspect people trying to do this may not have the correct mental model. #Resolved
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.
That's not the reason. This is only given for nullable reference types. The reason is that it is a runtime check, and nullable reference types do not exist at runtime. I'll clarify.
In reply to: 249944779 [](ancestors = 249944779)
…nce* types are illegal in an is-type or as-type expression.
I believe I have responded to all comments. Are there any further comments? #Resolved |
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.
LGTM Thanks (iteration 8)
} | ||
|
||
done:; |
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.
; [](start = 5, length = 1)
Minor point: ;
is unnecessary. #Resolved
@@ -3454,7 +3454,7 @@ static void Test(int arg1, (byte, byte) arg2) | |||
} | |||
"; | |||
var tree = SyntaxFactory.ParseSyntaxTree(source, options: TestOptions.Regular); | |||
Assert.Equal(false, tree.GetRoot().ContainsDiagnostics); | |||
tree.GetDiagnostics().Verify(); | |||
} |
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.
} [](start = 8, length = 1)
Are we testing: _ = new(int, int)?{};
? #Resolved
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.
Also test error recovery for: _ = new (int, int) ? (x) : y;
In reply to: 251128787 [](ancestors = 251128787)
result = ScanTypeFlags.NullableType; | ||
break; | ||
case SyntaxKind.AsteriskToken | ||
when lastTokenOfType.Kind != SyntaxKind.CloseBracketToken: // don't allow `Type[]*` |
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.
Type[]* [](start = 103, length = 7)
Are we testing this case? #Resolved
case ParseTypeMode.NewExpression: | ||
// A nullable qualifier is permitted as part of the type in a `new` expression. | ||
// e.g. `new int?()` is allowed. It creates a null value of type `Nullable<int>`. | ||
// But the object initializer syntax `new int? {}` is not permitted. |
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.
new int? {}
is not permitted [](start = 65, length = 30)
I'm confused. Should new int? { }
be permitted? (It is today.)
The comment says it's not permitted but the return
expression allows {
. #Resolved
@@ -16,15 +16,8 @@ private void VisitTypeSymbolWithAnnotations(TypeSymbolWithAnnotations type, Abst | |||
var visitor = (SymbolDisplayVisitor)(visitorOpt ?? this.NotFirstVisitor); |
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.
(SymbolDisplayVisitor) [](start = 26, length = 22)
The cast is no longer necessary. #Resolved
{ | ||
if (!this.isFirstSymbolVisited) | ||
if (!(arrayType is null) && !this.isFirstSymbolVisited) |
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.
(arrayType is null [](start = 21, length = 18)
while
condition already checked arrayType != null
. #Resolved
@@ -31,7 +31,11 @@ class C | |||
comp.VerifyDiagnostics( | |||
// (7,52): error CS1586: Array creation must have array size or array initializer | |||
// Expression<Action<dynamic>> e = x => new object[](x); | |||
Diagnostic(ErrorCode.ERR_MissingArraySize, "[]")); | |||
Diagnostic(ErrorCode.ERR_MissingArraySize, "[]").WithLocation(7, 52), | |||
// (7,42): error CS0149: Method name expected |
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.
error CS0149: Method name expected [](start = 27, length = 34)
This cascading error seems unfortunate. The first error makes sense but this second error seems incorrect given the first. #Resolved
} | ||
} | ||
EOF(); | ||
} |
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.
} [](start = 8, length = 1)
Please test with multiple dimensional array after ?
:
new object[1]?[2,3]?[]
``` #Resolved
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.
Several comments and some test suggestions, but not blocking.
TypeSyntax elementTypeSyntax = arrayTypeSyntax.ElementType; | ||
var elementType = BindType(elementTypeSyntax, diagnostics); | ||
var elementTypeSyntax = arrayTypeSyntax.ElementType; | ||
var arrayType = (ArrayTypeSymbol)BindArrayType(arrayTypeSyntax, diagnostics, permitDimensions: true, basesBeingResolved: null).TypeSymbol; |
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.
BindArrayType [](start = 45, length = 13)
I think this change is the cause of #33945
We didn't use to check whether the type is IsRestrictedType
, but now we do (inside BindArrayType
).
Fixes #32290 and other related issues