Skip to content

VB: Report non-Const locals used in an expression that must have a constant value.#49912

Merged
AlekseyTs merged 1 commit intodotnet:masterfrom
AlekseyTs:Issue49902
Dec 11, 2020
Merged

VB: Report non-Const locals used in an expression that must have a constant value.#49912
AlekseyTs merged 1 commit intodotnet:masterfrom
AlekseyTs:Issue49902

Conversation

@AlekseyTs
Copy link
Contributor

Fixes #49902.

If GetExpressionConstantValueIfAny(binaryOperator.Right, diagnostics, context) Is Nothing Then
nonConstantDetected = True
End If
GetExpressionConstantValueIfAny(binaryOperator.Right, diagnostics, context)
Copy link
Member

@RikkiGibson RikkiGibson Dec 10, 2020

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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)

@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

@AlekseyTs AlekseyTs merged commit 012f033 into dotnet:master Dec 11, 2020
@ghost ghost added this to the Next milestone Dec 11, 2020
333fred added a commit to 333fred/roslyn that referenced this pull request Dec 15, 2020
* 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)
  ...
@dibarbet dibarbet modified the milestones: Next, 16.9.P3 Dec 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug VB.NET misses the Error "The expression being assigned to '...' must be constant" and gives the misterious Error BC36970

5 participants