Skip to content

Commit 2ffe45e

Browse files
committed
Analyser: improve error message, add note
* add a note for the symbol definition when a non-public symbol is used this makes it much easier to add the missing `public` keyword
1 parent b8e4841 commit 2ffe45e

File tree

6 files changed

+6
-5
lines changed

6 files changed

+6
-5
lines changed

analyser/scope.c2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ public fn ast.Decl* Scope.findSymbolInModule(Scope* s, ast.Module* mod, u32 name
370370
if (mod != s.mod) {
371371
if (!d.isPublic()) {
372372
s.diags.error(loc, "symbol '%s' is not public", d.getFullName());
373+
s.diags.note(d.getLoc(), "symbol definition is here");
373374
return nil;
374375
}
375376
d.setUsedPublic();

test/expr/offsetof/offsetof_public.c2t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $warnings no-unused
44
// @file{file1}
55
module foo;
66

7-
type Foo struct {
7+
type Foo struct { // @note{symbol definition is here}
88
i32 x;
99
}
1010

test/module/using_private_var.c2t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// @file{file1}
55
module foo;
66

7-
i32 n;
7+
i32 n; // @note{symbol definition is here}
88

99
// @file{file2}
1010
module bar;

test/template/function/non_public_template.c2t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// @file{file1}
55
module file1;
66

7-
fn void test1(X arg1) template X {
7+
fn void test1(X arg1) template X { // @note{symbol definition is here}
88
}
99

1010
// @file{file2}

test/types/use_non_public_symbol_mod_prefix.c2t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// @file{file1}
55
module foo;
66

7-
const i32 Priv = 0;
7+
const i32 Priv = 0; // @note{symbol definition is here}
88

99
// @file{file2}
1010
module bar;

test/vars/use_non_public_symbol.c2t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// @file{file1}
55
module foo;
66

7-
const i32 Priv = 0;
7+
const i32 Priv = 0; // @note{symbol definition is here}
88

99
// @file{file2}
1010
module bar;

0 commit comments

Comments
 (0)