VB无法访问代码错误/警告 [英] VB Unreachable code error/warning

查看:202
本文介绍了VB无法访问代码错误/警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用VB.Net一年多,只是注意到这

I've been mostly working with VB.Net for over a year and just noticed this

我疯了,或者VB.Net NOT 有无法访问的代码警告?

Am I going insane, or does VB.Net NOT have an "Unreachable code" warning?

以下编译相当愉快与nary警告或错误,即使两个writeline调用之间有返回

The following compiles quite happily with nary a warning or error, even though there is a return between the two writeline calls.

Sub Main()
    Console.WriteLine("Hello World")
    Return
    Console.WriteLine("Unreachable code, will never run")
End Sub



我错过了什么?是否有一些方法可以切换到这种情况,我找不到。

Am I missing something? Is there some way to switch this on that I can't find.

如果没有,是否有一个很好的理由呢? (即我是对的,认为这是一个可悲的状态)

If not, is there a good reason for it's omission? (i.e. or am I right in thinking this is a woeful state of affairs)

原谅这个问题的空气,这不是一个rant,我想一个答案

Forgive the air of rant about this question, it's not a rant, I would like an answer.

感谢

a href =http://connect.microsoft.com =nofollow noreferrer> MS Connect ,作为错误#428529

I've raised this on MS Connect, as bug# 428529

更新

我从VB团队计划经理收到以下信息

I received the following from the VB Teams program manager


感谢您花费时间报告
这个问题。编译器在这种情况下限制了
支持,并且像
指出的那样,我们没有对
不可达代码的警告。有一些
场景,我们的流分析
算法处理,例如
如下:

Thanks for taking the time to report this issue. The compiler has limited support for this scenario, and as you point out we don't have warnings for unreachable code. There are some scenarios that our flow analysis algorithm does handle, such as the following:



Sub Main()
    Dim x As Integer
    Return
    x = 4
End Sub




在这种情况下,您会收到警告,表示
x从未被分配。对于
的情况你提到,但我们将有
看看执行一个
未来版本。

In this case you'll get a warning that x has never been assigned. For the case you mentioned however we'll have to look at implementing that for a future release.


推荐答案

我的猜测是,它是一个监督的编译器。流控制是一个非常困难的问题,在任何语言,但特别是在像VB这样的语言有如此多的不同的流控制机制得到正确。例如

My guess is that it's an oversight in the compiler. Flow control is a very difficult problem to get correct in any language, but especially in a language like VB which has so many different flow control mechanisms. For instance,


  • 例外

  • 转到

  • 错误(恢复,转到等...)

  • 退出通话

  • Exceptions
  • Goto
  • On Error (Resume, Goto, etc ...)
  • Exit calls

强烈关于此问题,连接上提出错误。我们确实通过Connect提交的错误非常认真,尽我们所能尽可能多地解决。

If you feel strongly about this issue, please file a bug on Connect. We do take bugs filed via Connect very seriously and do our best to fix as many as possible.

这篇关于VB无法访问代码错误/警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆