overload resolution failure, narrowing conversion

A

AMercer

I have a strange situation with vb 2005 regarding option strict that looks
like a compiler bug to me. Consider:

Dim f1 As New Font("Arial", 8.25)
Dim f2 As New Font("Arial", 8.25, FontStyle.Bold)

' f1 is ok with option strict on or off
' f2 is ok with strict on, but with off I get an overload resolution failure

The complete diagnostic is:

Overload resolution failed because no accessible 'New' can be called without
a narrowing conversion:
Public Sub New(familyName As String, emSize As Single, unit As
System.Drawing.GraphicsUnit)
: Argument matching parameter 'emSize' narrows from 'Double' to 'Single'.
Public Sub New(familyName As String, emSize As Single, unit As
System.Drawing.GraphicsUnit)
: Argument matching parameter 'unit' narrows from 'System.Drawing.FontStyle'
to 'System.Drawing.GraphicsUnit'.
Public Sub New(familyName As String, emSize As Single, style As
System.Drawing.FontStyle)
: Argument matching parameter 'emSize' narrows from 'Double' to 'Single'.

The following are also true:
Option Explicit is 'on'
Treat all warnings as errors is 'on'
Use if variable prior to assignment has notification 'none'
All other optional notifications are 'error'

It looks to me like the sense of the testing is backwards - it should
diagnose with strict on and allow with strict off. Additionally, it looks
like f1 and f2 should both succeed or both fail under the same compiler
settings/options since the complaint is about narrowing 8.25 from double to
single. FYI, one difference that may be in play is what you see with
intellisense. When you key in f1, you start with 13 available overloads, and
you end on 6. For f2, you start with 13 and end on 5.

Easy workarounds are available, namely using Csng() or use option strict.
Regardless, this looks like a vb compiler bug.
 
A

Armin Zingler

AMercer said:
I have a strange situation with vb 2005 regarding option strict that
looks like a compiler bug to me. Consider:

Seems so. Fixed in VB 2008.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top