Skip to content

Specify struct type in struct fields #36

@vklquevs

Description

@vklquevs

I tried to specify a struct name as a field type:

ketos=> (struct foo ((a string)))
foo
ketos=> (struct bar ((b foo)))
bar
ketos=> (new bar :b (new foo :a "fails"))
Traceback:

  In main, lambda
  In system function new

execution error: type error for field `b` of struct `bar`: expected foo; found struct: foo { a: "fails" }
ketos=> (struct baz ((b struct)))
baz
ketos=> (new baz :b (new foo :a "works"))
baz { b: foo { a: "works" } }

The error confused me for a while until I realized the type for all struct values is "struct". Could it allow you to specify a struct type for a field?

Also, the definition for bar was accepted, even though there is no such type foo - every attempt to create a bar will fail to typecheck!

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