wyvernlang / wyvern

The Wyvern programming language.
http://wyvernlang.github.io/
GNU General Public License v2.0
556 stars 65 forks source link

All types are extensible? #254

Open hcnelson99 opened 6 years ago

hcnelson99 commented 6 years ago

Low priority issue.

Test case:

type Foo
    val x: Unit

tagged type Bar extends Foo
    val x: Unit

Observed behavior: Clean compilation.

Expected behavior: Error because Foo isn't marked as extensible (a tagged type).

The generated CoreWyvernIL here also looks wrong:

seqexpr
    var_23 : type { ... } = new var_23 : type { ... } =>
        type Foo = type { ... }
        type Bar = datatype extends var_23.Foo comprises []

Bar is marked as a datatype with comprises [] implying no types should be able to extend it, but it instead should be marked as extag (openly extensible). Wyvern doesn't seem to be checking this comprises info anyways since it compiles if you add a type Baz extends Bar

hcnelson99 commented 6 years ago

You can elide the tagged as well and observed the same behavior. e.g.,

type Foo
    val x: Unit

type Bar extends Foo
    val x: Unit

Identical CoreWyvernIL is generated

JonathanAldrich commented 5 years ago

I'm thinking about the semantics of this one. Definitely you should not be able to extend a type that includes "comprises." So this is definitely a bug.

But if a type is not tagged, maybe "extends" should be allowed, and mean that the declared type is a subtype of the parent--and perhaps also that it inherits its parents members? This would require changing the core IL, probably, to represent "extends" without tagging. Something to think about.