From f10d813414256d11c17c9fb3a488194095d60fcf Mon Sep 17 00:00:00 2001 From: Mattia Giambirtone Date: Tue, 24 Jan 2023 12:08:29 +0100 Subject: [PATCH] Added visibility checks to forward declarations --- src/frontend/compiler/targets/bytecode/target.nim | 2 ++ tests/fwd.pn | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/frontend/compiler/targets/bytecode/target.nim b/src/frontend/compiler/targets/bytecode/target.nim index 1c373b7..121e649 100644 --- a/src/frontend/compiler/targets/bytecode/target.nim +++ b/src/frontend/compiler/targets/bytecode/target.nim @@ -538,6 +538,8 @@ proc patchForwardDeclarations(self: BytecodeCompiler) = var pos: array[8, uint8] for (forwarded, position) in self.forwarded: impl = self.match(forwarded.ident.token.lexeme, forwarded.valueType, allowFwd=false) + if forwarded.isPrivate != impl.isPrivate: + self.error(&"implementation of '{impl.ident.token.lexeme}' has a mismatching visibility modifier from its forward declaration", impl.ident) if position == 0: continue pos = impl.codePos.toLong() diff --git a/tests/fwd.pn b/tests/fwd.pn index ae25745..5525c7a 100644 --- a/tests/fwd.pn +++ b/tests/fwd.pn @@ -10,3 +10,5 @@ print(foo() == 42); fn foo: int {return 42;} # Commenting this line will cause an error +# Note: The forward declaration and its corresponding implementation +# must have the same visibility! \ No newline at end of file