Skip to content

Commit b4c1be5

Browse files
committed
Output errors BC30105 and BC30106 for incorrect accesses to elements of single and multi-dimensional arrays.
1 parent 46191be commit b4c1be5

File tree

7 files changed

+41
-8
lines changed

7 files changed

+41
-8
lines changed

vbnc/vbnc/source/Expressions/InvocationOrIndexExpression.vb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,13 @@ Public Class InvocationOrIndexExpression
368368
Return False
369369
End If
370370

371-
If CecilHelper.GetArrayRank(ArrayType) <> m_ArgumentList.Count Then
372-
Helper.AddError(Me, "Array dimensions are not correct.")
371+
Dim arrayRank As Integer = CecilHelper.GetArrayRank(ArrayType)
372+
373+
If m_ArgumentList.Count > arrayRank Then
374+
Compiler.Report.ShowMessage(Messages.VBNC30106, Location)
375+
Return False
376+
ElseIf m_ArgumentList.Count < arrayRank Then
377+
Compiler.Report.ShowMessage(Messages.VBNC30105, Location)
373378
Return False
374379
End If
375380

vbnc/vbnc/source/General/Messages.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,14 +695,14 @@ Public Enum Messages
695695
<Message(MessageLevel.Error)> VBNC30103 = 30103
696696

697697
''' <summary>
698-
''' VBNC = "CHANGEME"
698+
''' VBNC = "Number of indices is less than the number of dimensions of the indexed array."
699699
''' VB = "Number of indices is less than the number of dimensions of the indexed array."
700700
''' </summary>
701701
''' <remarks></remarks>
702702
<Message(MessageLevel.Error)> VBNC30105 = 30105
703703

704704
''' <summary>
705-
''' VBNC = "CHANGEME"
705+
''' VBNC = "Number of indices exceeds the number of dimensions of the indexed array."
706706
''' VB = "Number of indices exceeds the number of dimensions of the indexed array."
707707
''' </summary>
708708
''' <remarks></remarks>

vbnc/vbnc/source/Resources/Errors.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,10 @@
413413
<value>CHANGEME</value>
414414
</data>
415415
<data name="30105" xml:space="preserve">
416-
<value>CHANGEME</value>
416+
<value>Number of indices is less than the number of dimensions of the indexed array.</value>
417417
</data>
418418
<data name="30106" xml:space="preserve">
419-
<value>CHANGEME</value>
419+
<value>Number of indices exceeds the number of dimensions of the indexed array.</value>
420420
</data>
421421
<data name="30107" xml:space="preserve">
422422
<value>CHANGEME</value>

vbnc/vbnc/source/Resources/Source.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,12 @@
489489
</Message>
490490
<Message id="30105" level="Error">
491491
<Comment>NC</Comment>
492-
<VBNCValue>CHANGEME</VBNCValue>
492+
<VBNCValue>Number of indices is less than the number of dimensions of the indexed array.</VBNCValue>
493493
<VBValue>Number of indices is less than the number of dimensions of the indexed array.</VBValue>
494494
</Message>
495495
<Message id="30106" level="Error">
496496
<Comment>NC</Comment>
497-
<VBNCValue>CHANGEME</VBNCValue>
497+
<VBNCValue>Number of indices exceeds the number of dimensions of the indexed array.</VBNCValue>
498498
<VBValue>Number of indices exceeds the number of dimensions of the indexed array.</VBValue>
499499
</Message>
500500
<Message id="30107" level="Error">

vbnc/vbnc/tests/Errors/30105.vb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Module Main
2+
3+
Sub Foo
4+
5+
Dim mdarr(,) As String
6+
Dim var As String = mdarr(0)
7+
8+
End Sub
9+
10+
End Module

vbnc/vbnc/tests/Errors/30106.vb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Module Main
2+
3+
Sub Foo
4+
5+
Dim arr() As String
6+
Dim var As String = arr(0, 0)
7+
8+
End Sub
9+
10+
End Module

vbnc/vbnc/tests/tests.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24277,4 +24277,12 @@
2427724277
<file>Errors\30444.vb</file>
2427824278
<error line="6" number="30444" message="'Set' is already declared." />
2427924279
</test>
24280+
<test id="3146" name="30105" expectedexitcode="1" mytype="empty">
24281+
<file>Errors\30105.vb</file>
24282+
<error line="6" number="30105" message="Number of indices is less than the number of dimensions of the indexed array." />
24283+
</test>
24284+
<test id="3147" name="30106" expectedexitcode="1" mytype="empty">
24285+
<file>Errors\30106.vb</file>
24286+
<error line="6" number="30106" message="Number of indices exceeds the number of dimensions of the indexed array." />
24287+
</test>
2428024288
</rt>

0 commit comments

Comments
 (0)