Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The srcloc in grift0 is shifted for bingind structures with only one sub-expression in body. #116

Open
SuChengHao opened this issue Aug 30, 2023 · 0 comments

Comments

@SuChengHao
Copy link

The bug is caused by the parsing algorithm in src/grift/syntax->grift0.rkt.

For example, consider the following Grift program

(let ([a 1])
  (+ a 2))

The syntax->grift0 will give the following AST:

(Prog
 '("bad-let-2.grift" 1)
 (list
  (Ann2
   (Observe
    (Ann
     (Let
      (list
       (Bnd
        (Uid "a" 0)
        #f
        (Ann (Quote 1) (srcloc "bad-let-2.grift" 1 9 10 1))))
      (Ann
       (Op
        '+
        (list
         (Ann (Var (Uid "a" 0)) (srcloc "bad-let-2.grift" 2 5 19 1))
         (Ann (Quote 2) (srcloc "bad-let-2.grift" 2 7 21 1))))
       (srcloc "bad-let-2.grift" 1 0 1 23)))
     (srcloc "bad-let-2.grift" 1 0 1 23))
    #f)
   (srcloc "bad-let-2.grift" 1 0 1 23))))

The problem is that, the srcloc for (let ([a 1]) (+ a 2)) is exactly the srcloc for (+ a 2). Both of them are (1 0 1 1 23).

In general, the description of this bug is: if let or let-rec only has one expression in its body, then the srcloc of this expression will be the same as the outer let or let-rec.
I believe that is because of the weird logic of parse-begin. It seems that when the body of (begin e) only has one expression, this parsing algorithm will omit the outer begin. And all let, let-rec, define transform their bodies into a begin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant