mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Diagnose redundant redeclarations in impl files (#7695)
While forward declarations in impl files are allowed, having one in the impl file is redundant when we also have one in the API file.
This commit is contained in:
+33
-6
@@ -16,13 +16,10 @@ library "[[@TEST_NAME]]";
|
||||
|
||||
fn A();
|
||||
|
||||
// --- todo_fail_decl_in_api_definition_in_impl.impl.carbon
|
||||
// --- decl_in_api_definition_in_impl.impl.carbon
|
||||
|
||||
impl library "[[@TEST_NAME]]";
|
||||
|
||||
// TODO: This should be diagnosed per #3762: A declaration should always add new information.
|
||||
fn A();
|
||||
|
||||
fn A() {}
|
||||
|
||||
// --- use_decl_in_api.carbon
|
||||
@@ -55,12 +52,42 @@ fn C();
|
||||
|
||||
impl library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_decl_in_api_decl_in_impl.impl.carbon:[[@LINE+12]]:1: error: redeclaration of `fn C` is redundant [RedeclRedundant]
|
||||
// CHECK:STDERR: fn C();
|
||||
// CHECK:STDERR: ^~~~~~~
|
||||
// CHECK:STDERR: fail_decl_in_api_decl_in_impl.impl.carbon:[[@LINE-5]]:1: in import [InImport]
|
||||
// CHECK:STDERR: decl_in_api_decl_in_impl.carbon:4:1: note: previously declared here [RedeclPrevDecl]
|
||||
// CHECK:STDERR: fn C();
|
||||
// CHECK:STDERR: ^~~~~~~
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: fail_decl_in_api_decl_in_impl.impl.carbon:[[@LINE+4]]:1: error: no definition found for declaration in impl file [MissingDefinitionInImpl]
|
||||
// CHECK:STDERR: fn C();
|
||||
// CHECK:STDERR: ^~~~~~~
|
||||
// CHECK:STDERR:
|
||||
fn C();
|
||||
|
||||
// --- decl_in_api_decl_and_definition_in_impl.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
fn D();
|
||||
|
||||
// --- fail_decl_in_api_decl_and_definition_in_impl.impl.carbon
|
||||
|
||||
impl library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_decl_in_api_decl_and_definition_in_impl.impl.carbon:[[@LINE+8]]:1: error: redeclaration of `fn D` is redundant [RedeclRedundant]
|
||||
// CHECK:STDERR: fn D();
|
||||
// CHECK:STDERR: ^~~~~~~
|
||||
// CHECK:STDERR: fail_decl_in_api_decl_and_definition_in_impl.impl.carbon:[[@LINE-5]]:1: in import [InImport]
|
||||
// CHECK:STDERR: decl_in_api_decl_and_definition_in_impl.carbon:4:1: note: previously declared here [RedeclPrevDecl]
|
||||
// CHECK:STDERR: fn D();
|
||||
// CHECK:STDERR: ^~~~~~~
|
||||
// CHECK:STDERR:
|
||||
fn D();
|
||||
|
||||
fn D() {}
|
||||
|
||||
// --- decl_only_in_impl.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
@@ -70,7 +97,7 @@ library "[[@TEST_NAME]]";
|
||||
impl library "[[@TEST_NAME]]";
|
||||
|
||||
// CHECK:STDERR: fail_decl_only_in_impl.impl.carbon:[[@LINE+4]]:1: error: no definition found for declaration in impl file [MissingDefinitionInImpl]
|
||||
// CHECK:STDERR: fn D();
|
||||
// CHECK:STDERR: fn E();
|
||||
// CHECK:STDERR: ^~~~~~~
|
||||
// CHECK:STDERR:
|
||||
fn D();
|
||||
fn E();
|
||||
|
||||
Reference in New Issue
Block a user