summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2014-11-02 14:16:19 +0100
committerAndreas Rumpf <rumpf_a@web.de>2014-11-02 14:16:19 +0100
commit51c875863ee15a9e01b264cec64ec21e82531a64 (patch)
tree1cf7901bea801ccaa74063d170989c91224e8a14
parentef47a23b60eafd0179fe198049f94aca7c138fc1 (diff)
parenta8a9dd66991d5b5a46676e5202df642170dcb2f9 (diff)
downloadNim-51c875863ee15a9e01b264cec64ec21e82531a64.tar.gz
Merge pull request #1589 from Varriount/fix-1561
Fixes #1561
-rw-r--r--compiler/procfind.nim8
-rw-r--r--tests/modules/tmismatchedvisibility.nim9
2 files changed, 16 insertions, 1 deletions
diff --git a/compiler/procfind.nim b/compiler/procfind.nim
index 46d6c9929..473965a3d 100644
--- a/compiler/procfind.nim
+++ b/compiler/procfind.nim
@@ -11,7 +11,7 @@
 # This is needed for proper handling of forward declarations.
 
 import
-  ast, astalgo, msgs, semdata, types, trees
+  ast, astalgo, msgs, semdata, types, trees, strutils
 
 proc equalGenericParams(procA, procB: PNode): bool =
   if sonsLen(procA) != sonsLen(procB): return
@@ -68,11 +68,17 @@ proc searchForProcNew(c: PContext, scope: PScope, fn: PSym): PSym =
                  ExactConstraints, IgnoreCC}
 
   var it: TIdentIter
+
   result = initIdentIter(it, scope.symbols, fn.name)
   while result != nil:
     if result.kind in skProcKinds and sameType(result.typ, fn.typ, flags):
       case equalParams(result.typ.n, fn.typ.n)
       of paramsEqual:
+        if (sfExported notin result.flags) and (sfExported in fn.flags):
+          let message = ("public implementation '$1' has non-public " &
+                         "forward declaration in $2") %
+                        [getProcHeader(result), $result.info]
+          localError(fn.info, errGenerated, message)
         return
       of paramsIncompatible:
         localError(fn.info, errNotOverloadable, fn.name.s)
diff --git a/tests/modules/tmismatchedvisibility.nim b/tests/modules/tmismatchedvisibility.nim
new file mode 100644
index 000000000..6f2f79282
--- /dev/null
+++ b/tests/modules/tmismatchedvisibility.nim
@@ -0,0 +1,9 @@
+discard """
+  line: 8
+  errormsg: "public implementation 'tmismatchedvisibility.foo(a: int): int' has non-public forward declaration in tmismatchedvisibility.nim(6,5)"
+"""
+
+proc foo(a: int): int
+
+proc foo*(a: int): int =
+  result = a + a
\ No newline at end of file