tomhrr / dale

Lisp-flavoured C
BSD 3-Clause "New" or "Revised" License
1.02k stars 48 forks source link

Macro use segfault #236

Closed crumbtoo closed 1 week ago

crumbtoo commented 1 week ago

This code causes a mysterious segfault during compilation:

(import variant)
(import macros)

(using-namespace std.macros
  (def def-ordered-variant (macro intern (name cons)
    (qq def-variant (uq name) cons))))

;; segfault introduced here:
(def-ordered-variant Instr
  ((Doge ((a int)))
   Soge
   (Quoge ((a int) (b int)))))

(def main (fn extern-c
              int
              ((argc int)
               (argv (p (p char))))
  (return 0)))
$ dalec t.dt
zsh: segmentation fault  dalec t.dt
$ uname -a
Darwin fruitbook.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 x86_64
$ dalec --version
0.3 (rev 0e877b75)
tomhrr commented 1 week ago

Thanks, this was due to missing validation in def-variant. With that extra validation, the above produces:

test.dt:9:22: error: list required for variant members (see macro at 6:9)
test.dt:6:9: error: macro expansion error (see previous) (see macro at 9:1)

which is due to cons not being unquoted. Changing it to (uq cons) fixes the problem.