Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class method inheritance bug #10

Open
jneuendorf opened this issue Apr 12, 2017 · 3 comments
Open

class method inheritance bug #10

jneuendorf opened this issue Apr 12, 2017 · 3 comments

Comments

@jneuendorf
Copy link
Contributor

Hi,

apparently the tests I wrote for the class method inheritance (using super) are not sufficient.
Here is an example where the instance methods work correctly but the class methods do not:

class Widget
    @getDefaultProperties: () ->
        console.log "Widget"
        return {}
    getDefaultProperties: () ->
        console.log "Widget"
        return {}

class MoveableWidget extends Widget
class ResizeableWidget extends Widget
class MoveableResizableWidget extends heterarchy.multi MoveableWidget, ResizeableWidget

class ConfigurableWidget extends Widget
class HideableWidget extends ConfigurableWidget
    @getDefaultProperties: () ->
        console.log "HideableWidget"
        props = super()
        props.hidden = false
        return props
    getDefaultProperties: () ->
        console.log "HideableWidget"
        props = super()
        props.hidden = false
        return props

class TextWidget extends heterarchy.multi MoveableResizableWidget, HideableWidget
    @getDefaultProperties: () ->
        console.log "TextWidget"
        props = super()
        props.text = ""
        return props
    getDefaultProperties: () ->
        console.log "TextWidget"
        props = super()
        props.text = ""
        return props

console.log (new TextWidget).getDefaultProperties() # {"hidden":false,"text":""}
console.log TextWidget.getDefaultProperties() # {"text":""}
@arximboldi
Copy link
Owner

I see that both methods have the same name. Does the problem persist when they have different names?

@arximboldi
Copy link
Owner

Also, what is the output in that case in the terminal (i.e. in which classes and in what order does the method get called?)

@jneuendorf
Copy link
Contributor Author

jneuendorf commented Apr 12, 2017

concerning #10 (comment):
The original problem occurred without the instance methods with the same name (they were just added to show that everything works find with instance methods).
So I assume it has nothing to do with the method names.

concerning #10 (comment):
The output of the 1st call is (as expected):

TextWidget
HideableWidget
Widget

The 2nd call outputs:

TextWidget
Widget

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants