Added visibility checks to forward declarations

This commit is contained in:
Mattia Giambirtone 2023-01-24 12:08:29 +01:00
parent d16d4d5977
commit f10d813414
2 changed files with 4 additions and 0 deletions

View File

@ -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()

View File

@ -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!