ww imports: require imports before declarations

This commit is contained in:
2026-08-21 19:20:52 +09:00
parent b03bbb1428
commit ee4573bf55
9 changed files with 730 additions and 8 deletions

View File

@@ -249,9 +249,9 @@ main(void)
const char *src =
"package main;\n"
"import zed;\n"
"import alpha;\n"
"fn f() void = { let s: str = \"import fake;\"; };\n"
"/* import hidden; */\n"
"import alpha;\n";
"/* import hidden; */\n";
int errs;
const char *pkg;
char *got = imports_to_str(src, &errs, &pkg);
@@ -266,6 +266,28 @@ main(void)
free((void *)pkg);
free(got);
}
{
const char *src =
"package main;\n"
"fn first() void = {};\n"
"import alpha;\n"
"import beta;\n"
"fn second() void = {};\n"
"import gamma;\n";
int errs;
const char *pkg;
char *got = imports_to_str(src, &errs, &pkg);
if (errs != 2 || got == NULL
|| strstr(got, "(use \"alpha\"") == NULL
|| strstr(got, "(use \"beta\"") == NULL
|| strstr(got, "(use \"gamma\"") == NULL) {
fputs("late import sections were not diagnosed and retained\n",
stderr);
fail++;
}
free((void *)pkg);
free(got);
}
{
int errs;
const char *pkg;