Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Revert "Add more VB operator tests (#31320)" (#32439)
Browse files Browse the repository at this point in the history
This reverts commit 7c745fb.
  • Loading branch information
ViktorHofer authored Sep 24, 2018
1 parent e1416b7 commit 5d3db03
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7,158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Globalization
Imports System.Reflection
Imports System.Runtime.CompilerServices

Imports Microsoft.VisualBasic.CompilerServices.ExceptionUtils
Imports Microsoft.VisualBasic.CompilerServices.Symbols
Expand Down Expand Up @@ -888,7 +887,13 @@ Namespace Microsoft.VisualBasic.CompilerServices

Public Shared Function PlusObject(ByVal Operand As Object) As Object

If Operand Is Nothing Then
Return Boxed_ZeroInteger
End If

Dim typ As TypeCode = GetTypeCode(Operand)


Select Case typ

Case TypeCode.Empty
Expand Down Expand Up @@ -950,6 +955,13 @@ Namespace Microsoft.VisualBasic.CompilerServices
Public Shared Function NegateObject(ByVal Operand As Object) As Object

Dim tc As TypeCode = GetTypeCode(Operand)

If Operand Is Nothing Then
tc = TypeCode.Empty
Else
tc = Operand.GetType.GetTypeCode
End If

Select Case tc

Case TypeCode.Empty
Expand Down Expand Up @@ -1111,7 +1123,13 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function

Private Shared Function NegateDecimal(ByVal operand As Decimal) As Object
Return -operand
'Using try/catch instead of check with MinValue since the overflow case should be very rare
'and a compare would be a big cost for the normal case.
Try
Return -operand
Catch ex As OverflowException
Return -CDbl(operand)
End Try
End Function

Private Shared Function NegateSingle(ByVal operand As Single) As Object
Expand Down Expand Up @@ -2480,8 +2498,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
Case TypeCode.Empty * s_TCMAX + TypeCode.Decimal,
TypeCode.Empty * s_TCMAX + TypeCode.Single,
TypeCode.Empty * s_TCMAX + TypeCode.Double,
TypeCode.Empty * s_TCMAX + TypeCode.String,
TypeCode.DBNull * s_TCMAX + TypeCode.String
TypeCode.Empty * s_TCMAX + TypeCode.String

Return Right

Expand Down Expand Up @@ -2743,8 +2760,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
Case TypeCode.Decimal * s_TCMAX + TypeCode.Empty,
TypeCode.Single * s_TCMAX + TypeCode.Empty,
TypeCode.Double * s_TCMAX + TypeCode.Empty,
TypeCode.String * s_TCMAX + TypeCode.Empty,
TypeCode.String * s_TCMAX + TypeCode.DBNull
TypeCode.String * s_TCMAX + TypeCode.Empty

Return Left

Expand Down Expand Up @@ -4585,7 +4601,6 @@ Namespace Microsoft.VisualBasic.CompilerServices
Throw GetNoValidOperatorException(UserDefinedOperator.Modulus, Left, Right)
End Function

<MethodImpl(MethodImplOptions.NoInlining)> ' To work around https://github.com/dotnet/coreclr/issues/8648
Private Shared Function ModSByte(ByVal left As SByte, ByVal right As SByte) As Object
Return left Mod right
End Function
Expand All @@ -4595,18 +4610,27 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function

Private Shared Function ModInt16(ByVal left As Int16, ByVal right As Int16) As Object
Return left Mod right
Dim result As Integer = CInt(left) Mod CInt(right)

If result < Int16.MinValue OrElse result > Int16.MaxValue Then
Return result
Else
Return CShort(result)
End If
End Function

Private Shared Function ModUInt16(ByVal left As UInt16, ByVal right As UInt16) As Object
Return left Mod right
End Function

Private Shared Function ModInt32(ByVal left As Integer, ByVal right As Integer) As Object
If left = Integer.MinValue AndAlso right = -1 Then
Return 0
'Do operation with Int64 to avoid OverflowException with Int32.MinValue and -1
Dim result As Long = CLng(left) Mod CLng(right)

If result < Int32.MinValue OrElse result > Int32.MaxValue Then
Return result
Else
Return left Mod right
Return CInt(result)
End If
End Function

Expand Down Expand Up @@ -5107,30 +5131,9 @@ Namespace Microsoft.VisualBasic.CompilerServices
#Region " Operator Concatenate & "

Public Shared Function ConcatenateObject(ByVal Left As Object, ByVal Right As Object) As Object
Dim conv1, conv2 As IConvertible
Dim tc1, tc2 As TypeCode

conv1 = TryCast(Left, IConvertible)
If conv1 Is Nothing Then
If Left Is Nothing Then
tc1 = TypeCode.Empty
Else
tc1 = TypeCode.Object
End If
Else
tc1 = conv1.GetTypeCode()
End If

conv2 = TryCast(Right, IConvertible)
If conv2 Is Nothing Then
If Right Is Nothing Then
tc2 = TypeCode.Empty
Else
tc2 = TypeCode.Object
End If
Else
tc2 = conv2.GetTypeCode()
End If
Dim tc1 As TypeCode = GetTypeCode(Left)
Dim tc2 As TypeCode = GetTypeCode(Right)

'Special cases for Char()
If (tc1 = TypeCode.Object) AndAlso (TypeOf Left Is Char()) Then
Expand All @@ -5145,17 +5148,6 @@ Namespace Microsoft.VisualBasic.CompilerServices
Return InvokeUserDefinedOperator(UserDefinedOperator.Concatenate, Left, Right)
End If

Dim LeftIsNull As Boolean = (tc1 = TypeCode.DBNull)
Dim RightIsNull As Boolean = (tc2 = TypeCode.DBNull)

If LeftIsNull And RightIsNull Then
Return Left
ElseIf LeftIsNull And Not RightIsNull Then
Left = ""
ElseIf RightIsNull And Not LeftIsNull Then
Right = ""
End If

Return CStr(Left) & CStr(Right)
End Function

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
<Compile Include="Microsoft/VisualBasic/CompilerServices/StandardModuleAttributeTests.cs" />
<Compile Include="Microsoft/VisualBasic/Devices/NetworkAvailableEventArgsTests.cs" />
<Compile Include="ConversionsTests.cs" />
<Compile Include="DateAndTimeTests.cs" />
<Compile Include="OperatorsTests.cs" />
<Compile Include="OperatorsTests.Comparison.cs" />
<Compile Include="DateAndTimeTests.cs" />
<Compile Include="InformationTests.cs" />
<Compile Include="UtilsTests.cs" />
<Compile Include="VBMathTests.cs" />
Expand Down
Loading

0 comments on commit 5d3db03

Please sign in to comment.