Skip to content

typo in record passes compile #24

@bs76

Description

@bs76

I wrote this program, making a typo:

typedef tree<a>  = Leaf a | Node {left is tree , right is tree };

t1 is tree<number> = Node { left=Leaf 1,right=Node { left=Leaf 10, right=Leaf 2 }};

t2 is tree<number> = Node { left=Leaf 1,right=Node{ left=Leaf 2,rigt=Leaf 3 }};

println t1;
println t2;

walk t is tree<'a> -> list<'a> = (
    case t of 
    Leaf v : [v];
    Node {left,right} :  (walk left) ++ (walk right);
    esac;
    );

println(walk t1);
println(walk t2);

in t2 the last node is rigt not right. Compile passes and program fails with:

Node {left=Leaf 1, right=Node {left=Leaf 10, right=Leaf 2}}
Node {left=Leaf 1, right=Node {left=Leaf 2, rigt=Leaf 3}}
[1,10,2]
java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
        at yeti.lang.Struct3.get(Struct3.java:50)
        at x$walk.apply(x.yeti)
        at x$walk.apply(x.yeti:17)
        at x.main(x.yeti:22)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at yeti.lang.compiler.eval._1(eval.yeti:102)
        at yeti.lang.compiler.eval.execClass(eval.yeti:76)
        at yeti.lang.compiler.eval$compileYetiFiles$.apply(eval.yeti:354)
        at yeti.lang.compiler.yeti._3(yeti.yeti:231)
        at yeti.lang.compiler.yeti.main(yeti.yeti:224)

Am I doing something wrong or is it a bug ?

Using yeti 1.0

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