ww imports: require imports before declarations
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Declaration-before-import twin of ../modfn_coexist/main.ww. The distinct
|
||||
// local name follows Go's import/package-scope collision rule while retaining
|
||||
// the order-independence check for installing a real import binding.
|
||||
// Reordered-source twin of ../modfn_coexist/main.ww. The distinct local name
|
||||
// follows Go's import/package-scope collision rule while retaining the
|
||||
// declaration/import installation-order check for a real file-scoped binding.
|
||||
package main;
|
||||
fn localaa() i32 = { return 1; };
|
||||
import aa;
|
||||
fn localaa() i32 = { return 1; };
|
||||
export fn main() i32 = { return localaa() + aa.helper(); };
|
||||
|
||||
Reference in New Issue
Block a user