Skip to content

Commit

Permalink
fixes #5439
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Feb 26, 2017
1 parent 53f4bda commit fb37d13
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ proc cgsym(m: BModule, name: string): Rope =

proc generateHeaders(m: BModule) =
add(m.s[cfsHeaders], tnl & "#include \"nimbase.h\"" & tnl)

for it in m.headerFiles:
if it[0] == '#':
add(m.s[cfsHeaders], rope(it.replace('`', '"') & tnl))
Expand Down Expand Up @@ -1377,9 +1377,10 @@ proc myClose(graph: ModuleGraph; b: PPassContext, n: PNode): PNode =
registerModuleToMain(m.g, m.module)

if sfMainModule in m.module.flags:
incl m.flags, objHasKidsValid
var disp = generateMethodDispatchers(graph)
for i in 0..sonsLen(disp)-1: genProcAux(m, disp.sons[i].sym)
if m.g.forwardedProcsCounter == 0:
incl m.flags, objHasKidsValid
let disp = generateMethodDispatchers(graph)
for x in disp: genProcAux(m, x.sym)
genMainProc(m)

proc cgenWriteModules*(backend: RootRef, config: ConfigRef) =
Expand Down
27 changes: 27 additions & 0 deletions tests/ccgbugs/twrong_method.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
discard """
cmd: "nim c -d:release $file"
output: '''correct method'''
"""
# bug #5439
type
Control* = ref object of RootObj

ControlImpl* = ref object of Control

Container* = ref object of ControlImpl

ContainerImpl* = ref object of Container

method testProc*(control: Control) {.base.} = echo "wrong method"

method testProc*(container: Container) = echo "correct method"

proc main()

main() # wrong method called

proc main() =
var container = new ContainerImpl
container.testProc()

# main() # correct method called

0 comments on commit fb37d13

Please sign in to comment.