Skip to content

Commit 53fcaa0

Browse files
committed
errors
1 parent 9aaeadc commit 53fcaa0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/dmd/errors.d

+26
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,32 @@ private void verrorPrint(const ref Loc loc, Color headerColor, const(char)* head
236236
else
237237
fputs(tmp.peekString(), stderr);
238238
fputc('\n', stderr);
239+
240+
auto fp = fopen(loc.filename, "r");
241+
scope(exit) fclose(fp);
242+
243+
if (fp)
244+
{
245+
char* lineptr;
246+
ulong n = 1024;
247+
import core.sys.posix.stdio;
248+
foreach (_; 0 .. loc.linnum)
249+
{
250+
if (lineptr is null)
251+
goto end;
252+
assert(getline(&lineptr, &n, fp) > 0);
253+
}
254+
if (lineptr is null)
255+
goto end;
256+
fprintf(stderr, "%s", lineptr);
257+
258+
foreach (_; 0 .. loc.charnum)
259+
fputc(' ', stderr);
260+
261+
fputc('^', stderr);
262+
}
263+
fputc('\n', stderr);
264+
end:
239265
fflush(stderr); // ensure it gets written out in case of compiler aborts
240266
}
241267

0 commit comments

Comments
 (0)