adam-mcdaniel / sage

A programming language that's wise beyond its bytes!🌱🌿🪴
https://adam-mcdaniel.net/sage-website
MIT License
414 stars 15 forks source link

Better type checking #27

Closed adam-mcdaniel closed 1 year ago

adam-mcdaniel commented 1 year ago

Added a simple fix to make type-checking better for the Let type.

Previously, the following program would return a nonsense error Symbol "B" not defined:

const putint = proc(i: Int) -> None = std {
    put-int [SP]
    pop
} in

type List = let B = let T = Int in (T, &B) in B in

let x = (3, Null),
    y = (2, &x),
    z: List = (1, &y),
    in putint(z.1->1->0)

This should not fail, but it's due to a simple bug caused by not simplifying the Let type before returning in get_member_offset, causing undefined symbols (which are defined in the Let scope) to be left in the returned type.

Now, the following program type-checks as expected:

const putint = proc(i: Int) -> None = std {
    put-int [SP]
    pop
} in

type List = let B = let T = Int in (T, &B) in B in

let x = (3, Null),
    y = (2, &x),
    z: (let A = (Int, &A) in A) = (1, &y),
    w: List = (0, &z)
    in putint(w.1->1->1->0)