VB: Report non-Const locals used in an expression that must have a constant value.#49912
VB: Report non-Const locals used in an expression that must have a constant value.#49912AlekseyTs merged 1 commit intodotnet:masterfrom
Conversation
| If GetExpressionConstantValueIfAny(binaryOperator.Right, diagnostics, context) Is Nothing Then | ||
| nonConstantDetected = True | ||
| End If | ||
| GetExpressionConstantValueIfAny(binaryOperator.Right, diagnostics, context) |
There was a problem hiding this comment.
Does this change cause some expressions that used to be considered constant to no longer be considered constant? Do we need breaking change documentation for that? #Resolved
There was a problem hiding this comment.
Does this change cause some expressions that used to be considered constant to no longer be considered constant?
Not really. We wouldn't get here if an expression was considered a constant. See the comment right below Case BoundKind.BinaryOperator and, based on review of the algorithm, I think it is accurate. Given that, unless there is a bug similar to the one I am fixing, an error is going to be reported anyway. What we could end up with before is that, despite an error, a ConstantValue for a left operand of a binary operator could be returned. That value, clearly, doesn't represent the result of a binary operator itself and perhaps could have wrong type. That probably could affect what our internal structures hold and the constant value that SemanticModel or a symbol reports, but I do not consider that a breaking change. Compiler simply becomes more "accurate" in error scenarios.
In reply to: 540555923 [](ancestors = 540555923)
|
@dotnet/roslyn-compiler Please review |
* upstream/master: (241 commits) Allow pattern matching `null` against pointer types when the pointer types contain nested type parameters (dotnet#49915) Remove document extension method and convert usages to use the text buffer extension method. VB: Strengthen implementation of `PropertySymbol.IsWritable` against NullReferenceException (dotnet#49962) Add switch to skip nullable analysis (dotnet#49876) Update dependencies from https://github.com/dotnet/roslyn build 20201211.16 (dotnet#49958) Treat record positional parameters as properties (dotnet#48329) [master] Update dependencies from dotnet/roslyn (dotnet#49395) VB: Ensure array access indexes undergo conversion to integer even when there is a mismatch with array rank. (dotnet#49907) Disable OOP when running as cloud environment client VS instance Rename workspace context method (and unify impls) to better represent the condition being checked Report non-Const locals used in an expression that must have a constant value. (dotnet#49912) Add support for more ServiceAudience values (dotnet#49914) Handle ref-containing structs returned by value from function-pointers (dotnet#49883) Fix error on out param of extern local function (dotnet#49860) Fix constructor exit warnings for generic NotNull (dotnet#49841) Loc updates Prefer more specific path map key (dotnet#49670) Rename `_availablelocalFunctionOrdinal` to `_availableLocalFunctionOrdinal` (dotnet#49901) Fix namespace so that external access wrapper type can be accessed from UT. XamlProjectService fixes (dotnet#49711) ...
Fixes #49902.