andrep / hoc

Automatically exported from code.google.com/p/hoc
8 stars 1 forks source link

"super" does not chain properly on Mac OS 10.5.5 #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Steps to reproduce the problem:
1. Define a class with a method that calls super
2. Subclass that class
3. Call the method that calls super on the subclass

- What I expect is that call to super should dispatch to the implementation 
from the class above the class implementing that 
version of the method.
- What I see is that the call goes to the superclass of the implementation of 
the object, triggering an infinite loop of calls to 
that same implementation until the stack overflows.

The following code exhibits the behavior I am seeing:

{-# LANGUAGE TemplateHaskell, TypeSynonymInstances, FlexibleInstances,
        MultiParamTypeClasses, DeriveDataTypeable #-}
module Main where

import HOC
import Foundation (NSObject, NSObjectClass, alloc, init)
import Prelude hiding (init)

$(declareSelector "sayHi" [t| IO () |])

$(declareClass "Hello" "NSObject")
$(exportClass "Hello" "hello_" [
        InstanceMethod 'sayHi
    ])

hello_sayHi self = do
    putStrLn "hi!"

$(declareClass "Howdy" "Hello")
$(exportClass "Howdy" "howdy_" [
        InstanceMethod 'sayHi
        ])

howdy_sayHi self = do
    putStrLn "About to say hi:"
    super self # sayHi

$(declareClass "Antisocial" "Howdy")
$(exportClass "Antisocial" "" [])
instance Has_sayHi (Hello a)

main = do
    initializeClass_Hello
    initializeClass_Howdy
    initializeClass_Antisocial

    me <- _Antisocial # alloc >>= init
    me # sayHi

Original issue reported on code.google.com by james.c...@usma.edu on 8 Dec 2008 at 7:50

GoogleCodeExporter commented 9 years ago
Based on what I see in Super.hs I expect this to happen on all runtimes, unless 
I'm missing some kind of 
magic.

The problem is especially noticeable though when using cocoa bindings, because 
it seems that the cocoa 
binding subsystem adds a subclass that then poses as the original class - so 
"super" becomes a guaranteed 
infinite loop.

Original comment by james.c...@usma.edu on 8 Dec 2008 at 8:03

GoogleCodeExporter commented 9 years ago
Fixed in r368.

Original comment by james.c...@usma.edu on 9 Dec 2008 at 8:30