dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Errors in any function's signature hides errors in other function bodies

Open vpanteleev-sym opened this issue 8 months ago • 3 comments

void f1() {
	seriousError();
}

void f2(SomeType x) {
}

The compiler is not reporting any errors in f1 because f2's signature has errors, even though f1 is completely unrelated to f2.

Ideally, the compiler should recognize that the two functions are unrelated, and report errors in both, instead of only the second.

vpanteleev-sym avatar Apr 12 '25 07:04 vpanteleev-sym

I think that is by design: - 'function parameter types and return type' is the first semantic phase, function bodies is the third semantic phase.

The "semantic" phase will analyze the full signature of all declarations ... The "semantic3" phase will analyze the body of function declarations.

https://wiki.dlang.org/DMD_Source_Guide#Compilation_cycle

ntrel avatar Apr 12 '25 15:04 ntrel

Why stop at phase 1 and halt compilation entirely, instead of marking the bad objects as bad and continuing to the next phase?

vpanteleev-sym avatar Apr 12 '25 15:04 vpanteleev-sym

I checked to see how other languages and their compilers behave in this situation:

long Compiler Explorer link

The only language I found that behaved the same was Crystal. All other languages I tried report errors simultaneously in function signatures and bodies.

vpanteleev-sym avatar Apr 12 '25 15:04 vpanteleev-sym