Skip to content

Inheriting from BigDecimal returns incorrect class #198

@dekz

Description

@dekz

When creating a subclass of BigDecimal the class returned on construction is BigDecimal and not the extended class. Discovered by @kouno.

Construction inside RubyBigDecimal.java seems to be the cause of the issue. All BigDecimal#new calls seem to call the BigDecimal argumented constructor.

    public RubyBigDecimal(Ruby runtime, BigDecimal value) {
        super(runtime, runtime.getClass("BigDecimal"));
        this.value = value;
    }

This should be replaced with a helper constructor that takes into account this.metaClass

    private RubyBigDecimal createBigDecimal(Ruby runtime, BigDecimal value) {
        return new RubyBigDecimal(runtime, this.getMetaClass(), value);
    }

And all constructions from operations should use this.

https://gist.github.com/2878757

SHA: 02002ed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions