SemanticModel.GetSymbolInfo() on VB syntax node AddAssignmentStatement returns always null

Topics: APIs
Aug 28, 2014 at 1:46 PM
I expected to get the ISymbol of an operator.

Let's take an example:
Dim a As String = "Hello "
a += "world!"        ' here is an AddAssignmentStatement node
                     ' on which SemanticModel.GetSymbolInfo() returns null
according to the VB langage specification the previous statement is supposed to be equivalent to :
a = a + "world!"   ' here is an AddExpression node
                   ' on which SemanticModel.GetSymbolInfo() 
                   ' returns a concatenation operator defined as :
                   ' Public Shared Operator &(left As String, right As String) As String
Could it mean that the first is resolve at runtime? (for what purpose!?) I do not think so, but then why a such difference? Is it a bug?

I observed the same behavior with all compound operators.
Developer
Aug 28, 2014 at 8:15 PM
AddAssignmentStatement includes the following code:
a += "world!"
AddExpression only includes
a + "world!"
SimpleAssignmentStatement includes
a = a + "world!"
AddExpression obviously has a symbol because you could call MyMethod(a + "World") and it would compile.
However, a += "World!" is a statement, meaning that it is invalid to say MyMethod(a += "World").
I should also note that GetSymbolInfo will return null if you pass in the SimpleAssignmentStatement of a = a + "world!" because it would be incorrect to say MyMethod(a = a + "world!").

Even though AddAssignmentStatement and AddExpression + SimpleAssignmentStatement have the same meaning from a program execution standpoint they mean different things when looking up symbols.
Aug 28, 2014 at 9:21 PM
Edited Aug 28, 2014 at 9:25 PM
Ok, I understand now why a such behavior. My problem comes from the fact that compound operations (as well as simple assignments) are not considered as expression statements (as in C#) but as statements, and GetSymbolInfo return null on statements.

Although I now understand what happen, it still seems strange to me that there is no way to get the same kind of symbol information on a += operator as with Roslyn C#. Ok these languages do not have the same design (at all!) but the += operator have the same semantic in both languages.

Thanks for your answer.
Developer
Aug 28, 2014 at 9:43 PM
I think its reasonable to be able to get this information. Perhaps we should provide something similar to GetForEachStatementInfo for assignment statements. Could you create an issue to track this?
Aug 29, 2014 at 8:39 AM