简体   繁体   English

C#编译器在每次编译时不会立即报告所有错误吗?

[英]Is C# compiler not reporting all errors at once at each compile?

When I am compiling this project, it show like 400+ errors in the Error List window, then I go to error sites, fix some, and the number goes to say 120+ errors, and then after fixing some more, the next compile reports like 400+ again. 当我编译这个项目时,它在错误列表窗口中显示400多个错误,然后我转到错误站点,修复一些,然后数字说120+错误,然后在修复一些之后,下一个编译报告再次像400+。 I can see that different files are coming in in the Error List window, so I am thinking the compiler aborts after a certain number of errors? 我可以看到错误列表窗口中出现了不同的文件,所以我认为编译器在发生一定数量的错误后会中止?

If so, what's the reason for this? 如果是这样,原因是什么? Is it not supposed to gather all the errors that are present in the project even if they are over 10K+? 它是否应该收集项目中存在的所有错误,即使它们超过10K +?

I've been meaning to write a blog article about this. 我一直想写一篇关于此的博客文章。

It is possible that you're simply running into some hard-coded limit for the number of errors reported. 对于报告的错误数量,您可能只是遇到了一些硬编码限制。 It's also possible that you're running into a more subtle and interesting scenario. 你也可能遇到一个更微妙和有趣的场景。

There are a lot of heuristics in the command-line compiler and the IDE compiler that attempt to manage error reporting. 命令行编译器和IDE编译器中有许多试图管理错误报告的启发式方法。 Both to keep it manageable for the user, and to make the compiler more robust. 两者都是为了让用户可以管理,并使编译器更加健壮。

Briefly, the way the compiler works is it tries to get the program through a series of stages, which you can read about here: 简而言之,编译器的工作方式是尝试通过一系列阶段获取程序,您可以在这里阅读:

http://blogs.msdn.com/b/ericlippert/archive/2010/02/04/how-many-passes.aspx http://blogs.msdn.com/b/ericlippert/archive/2010/02/04/how-many-passes.aspx

The idea is that if an early stage gets an error, we might not be able to successfully complete a later stage without (1) going into an infinite loop, (2) crashing, or (3) reporting crazy "cascading" errors. 我们的想法是,如果早期阶段出现错误,我们可能无法在没有(1)进入无限循环,(2)崩溃或(3)报告疯狂的“级联”错误的情况下成功完成后续阶段。 So what happens is, you get one error, you fix it, and then suddenly the next stage of compilation can run, and it finds a bunch more errors. 所以会发生什么,你得到一个错误,你修复它,然后突然下一个编译阶段可以运行,它会发现更多的错误。

Basically, if the program is so messed up that we cannot even verify basic facts about its classes and methods, then we can't reliably give errors for method bodies. 基本上,如果程序如此混乱以至于我们甚至无法验证有关其类和方法的基本事实,那么我们就无法可靠地为方法体提供错误。 If we can't analyze a lambda body, then we can't reliably give errors for its conversion to an expression tree. 如果我们无法分析lambda体,那么我们就无法可靠地为其转换为表达式树提供错误。 And so on; 等等; there are lots of situations where later stages need to know that the previous stages completed without errors. 在很多情况下,后期阶段需要知道前面的阶段完成没有错误。

The up side of this design is that (1) you get the errors that are the most "fundamental" first, without a lot of noisy, crazy cascading errors, and (2) the compiler is more robust because it doesn't have to try to do analysis on programs where the basic invariants of the language are broken. 这种设计的好处在于:(1)你首先得到最“基本”的错误,没有很多嘈杂,疯狂的级联错误,以及(2)编译器更强大,因为它不需要尝试对语言的基本不变量被破坏的程序进行分析。 The down side is of course your scenario: that you have fifty errors, you fix them all, and suddenly fifty more appear. 缺点当然是你的情况:你有50个错误,你修复它们,突然又出现了50个。

Of course it will stop at some point. 当然它会在某个时候停止。

Even after 1 error, all the rest is dubious at best. 即使在1次错误之后,其余的都是可疑的。 A compiler will try to recuperate, but that's not guaranteed to succeed. 编译器将尝试恢复,但不能保证成功。

So in any non-trivial project, it's a practical decision between stopping at the first error (theoretically the best thing to do) and ploughing on in an unreliable state. 因此,在任何非平凡的项目中,在停止第一个错误(理论上最好的事情)和在不可靠的状态下耕作之间是一个实际的决定。

The most correct action would be to stop after 1 error, but that would lead to a tedious 'fix 1 at a time' situation. 最正确的操作是在1次错误后停止,但这会导致繁琐的“一次修复1”情况。 So a compiler tries to resync to a known state and report the next one. 因此编译器会尝试重新同步到已知状态并报告下一个状态。 But an error could cause false errors in correct code following it, so at some point it stops being sensible. 但是错误可能会导致跟随它的正确代码出现错误错误,所以在某些时候它会停止合理。

Refer to your own case: 400+ goes to 120 after a few fixes. 请参考您自己的案例:经过一些修复后,400+会变为120。

It's configurable according to MSDN 它可以根据MSDN进行配置

By default, the maximum number is 200 errors and warnings. 默认情况下,最大数量为200个错误和警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM