wyvernlang / wyvern

The Wyvern programming language.

Home Page:http://wyvernlang.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extends not type safe

hcnelson99 opened this issue · comments

Test case:

type T
    def foo(): Int

type S extends T
    def bar(): Int

def makeS(): S = new
    def bar(): Int = 1

val x: T = makeS()
x.foo()

Observed behavior: Called method foo, but the method does not exist on the receiver object. Did you use type Dyn? at location file objalg.wyv on line 7 column 18

Expected behavior: type S is not allowed to extend T unless S is a subtype of T.

Nicer solution: Implement inheritance (extends keyword copies methods of T into S so S is automatically a subtype of T without code duplication). This would help in writing object algebras for the js backend.

Workaround: Manually copy methods of T into S.