3 ms·
in d: import std.stdio; alias string = immutable(char)[] void main() { bar(foo()); } void bar(string s) { writeln(s); } string foo() { return "foo";
by norir 2y ago
in d:
import std.stdio;
alias string = immutable(char)[]
void main() { bar(foo()); }
void bar(string s) { writeln(s); }
string foo() { return "foo"; }
now change the definition of foo:
import std.stdio;
alias string = immutable(char)[];
void main() { bar(foo()); }
void bar(string s) { writeln(s); }
int foo() { return 1; }
This now fails to compile at line 3 even though the breaking change was made at line 5.
- me-vs-cat 2y agoI am unable to fit that example in this prior description: "if I append to the source file, I can't break previously correct code above the insertion point". Can you help me by providing the "previously correct code" and the "appended code" which causes the break after being appended?
- me-vs-cat 2y agoI am unable to fit that example in this prior description: "if I append to the source file, I can't break previously correct code above the insertion point". Your foo() example above has code which has been changed, rather than "if I append to the source file". (I re-read my prior comment and realized this may not have been clear.) That a change to code can introduce a bug is something we've all seen. But your prior description is not any kind of change, it was specifically an append. In the context of forward references, I am curious to see something that matched your prior description.