470,594 Members | 1,273 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

overload resolution failure, narrowing conversion

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.

Jan 4 '08 #1
1 3333
"AMercer" <AM*****@discussions.microsoft.comschrieb
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
Jan 4 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Alexander Stippler | last post: by
7 posts views Thread by Richard Hayden | last post: by
reply views Thread by Eph0nk | last post: by
5 posts views Thread by Gang Zhang | last post: by
2 posts views Thread by sri | last post: by
2 posts views Thread by xtrigger303 | last post: by
9 posts views Thread by sebastian | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.