Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VB.NET compiler erroneously reports error BC30439 when converting certain large Double values to Long #73032

Closed
MichaelJLiu opened this issue Apr 15, 2024 · 0 comments · Fixed by #73016

Comments

@MichaelJLiu
Copy link
Contributor

Any constant or literal Double should be convertible to Long at compile time if its value is within the range of the Long data type (approximately ±9.223E+18). However, if the value is a large positive number between &H7000000000000400L and &H7FFFFFFFFFFFFC00L, then the error "BC30439: Constant expression not representable in type 'Long'." occurs:

Console.WriteLine(CType(9.0E+18, Long))
'                       ~~~~~~~
Console.WriteLine(CType(CDbl(&H7000000000000400L), Long))
'                       ~~~~~~~~~~~~~~~~~~~~~~~~~
Console.WriteLine(CType(CDbl(&H7FFFFFFFFFFFFC00L), Long))
'                       ~~~~~~~~~~~~~~~~~~~~~~~~~

' Expected behavior: No errors.
' Actual behavior: Error BC30439 is reported on each line as indicated.

This bug does not affect Double values in the range &H8000000000000000L (Long.MinValue) through &H7000000000000000L:

Console.WriteLine(CType(-9.0E+18, Long))                  ' -9000000000000000000
Console.WriteLine(CType(CDbl(&H8000000000000000L), Long)) ' -9223372036854775808
Console.WriteLine(CType(CDbl(&H8000000000000400L), Long)) ' -9223372036854774784
Console.WriteLine(CType(CDbl(&H8FFFFFFFFFFFFC00L), Long)) ' -8070450532247929856
Console.WriteLine(CType(CDbl(&H9000000000000000L), Long)) ' -8070450532247928832
Console.WriteLine(CType(CDbl(&H7000000000000000L), Long)) '  8070450532247928832

' Expected and actual behavior: No errors.

This bug also does not affect run-time conversions:

Dim a = 9.0E+18
Dim b = CDbl(&H7000000000000400L)
Dim c = CDbl(&H7FFFFFFFFFFFFC00L)
Console.WriteLine(CType(a, Long)) ' 9000000000000000000
Console.WriteLine(CType(b, Long)) ' 8070450532247929856
Console.WriteLine(CType(c, Long)) ' 9223372036854774784

' Expected and actual behavior: No errors.

It looks like this bug affects all versions of the VB.NET compiler, including pre-Roslyn versions like C:\Windows\Microsoft.NET\Framework\v2.0.50727\vbc.exe.

This bug does not affect the C# compiler.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 15, 2024
@jaredpar jaredpar added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 16, 2024
@jaredpar jaredpar added this to the 17.11 milestone Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants