Correct false positive check in check_unique_package_names

This commit is contained in:
gingerBill
2022-01-31 19:33:02 +00:00
parent 2f1aeaf757
commit 67ba05cb7c
3 changed files with 19 additions and 2 deletions

View File

@@ -5307,12 +5307,18 @@ void check_unique_package_names(Checker *c) {
string_map_set(&pkgs, key, pkg);
continue;
}
auto *this = pkg->files[0]->pkg_decl;
auto *other = (*found)->files[0]->pkg_decl;
if (this == other) {
// NOTE(bill): A false positive was found, ignore it
continue;
}
error(pkg->files[0]->pkg_decl, "Duplicate declaration of 'package %.*s'", LIT(name));
error(this, "Duplicate declaration of 'package %.*s'", LIT(name));
error_line("\tA package name must be unique\n"
"\tThere is no relation between a package name and the directory that contains it, so they can be completely different\n"
"\tA package name is required for link name prefixing to have a consistent ABI\n");
error((*found)->files[0]->pkg_decl, "found at previous location");
error(other, "found at previous location");
}
}

View File

@@ -183,6 +183,11 @@ Ast *clone_ast(Ast *node) {
n->FieldValue.value = clone_ast(n->FieldValue.value);
break;
case Ast_EnumFieldValue:
n->EnumFieldValue.name = clone_ast(n->EnumFieldValue.name);
n->EnumFieldValue.value = clone_ast(n->EnumFieldValue.value);
break;
case Ast_TernaryIfExpr:
n->TernaryIfExpr.x = clone_ast(n->TernaryIfExpr.x);
n->TernaryIfExpr.cond = clone_ast(n->TernaryIfExpr.cond);

View File

@@ -39,6 +39,7 @@ Token ast_token(Ast *node) {
case Ast_SliceExpr: return node->SliceExpr.open;
case Ast_Ellipsis: return node->Ellipsis.token;
case Ast_FieldValue: return node->FieldValue.eq;
case Ast_EnumFieldValue: return ast_token(node->EnumFieldValue.name);
case Ast_DerefExpr: return node->DerefExpr.op;
case Ast_TernaryIfExpr: return ast_token(node->TernaryIfExpr.x);
case Ast_TernaryWhenExpr: return ast_token(node->TernaryWhenExpr.x);
@@ -178,6 +179,11 @@ Token ast_end_token(Ast *node) {
}
return node->Ellipsis.token;
case Ast_FieldValue: return ast_end_token(node->FieldValue.value);
case Ast_EnumFieldValue:
if (node->EnumFieldValue.value) {
return ast_end_token(node->EnumFieldValue.value);
}
return ast_end_token(node->EnumFieldValue.name);
case Ast_DerefExpr: return node->DerefExpr.op;
case Ast_TernaryIfExpr: return ast_end_token(node->TernaryIfExpr.y);
case Ast_TernaryWhenExpr: return ast_end_token(node->TernaryWhenExpr.y);