Skip to content

Class Parameter Inheritance duplicate names #528

@mkhan45

Description

@mkhan45

The example uses a and b in the superclass, and then x and y in the subclasses with implicit constructor:

// With class parameters:
// implicit field declarations and constructor
class IntPair(a: int, b: int) {
    def sum() -> int {
        return a + b;
    }
}

...

// Alternative C:
// class parameters, implicit constructor and call to super
class IntTripleC(x: int, y: int, c: int) extends IntPair(x, y) {
    def sum() -> int {
        return a + b + c;
    }
}

I expect this to work fine when I reuse the field names, but it errors:

// With class parameters:
// implicit field declarations and constructor
class IntPair(a: int, b: int) {
    def sum() -> int {
        return a + b;
    }
}

...

// Alternative C:
// class parameters, implicit constructor and call to super
class IntTripleC(a: int, b: int, c: int) extends IntPair(a, b) {
    def sum() -> int {
        return a + b + c;
    }
}
> v3c test.v3
[test.v3 @ 27:18] MemberRedefined: member "a" redefined
class IntTripleC(a: int, b: int, c: int) extends IntPair(a, b) {
                 ^
[test.v3 @ 27:26] MemberRedefined: member "b" redefined
class IntTripleC(a: int, b: int, c: int) extends IntPair(a, b) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions