Skip to content

Commit 94161d0

Browse files
committed
Bug in struct match.
1 parent 4f03ae3 commit 94161d0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

langs/neerdowell/compile-expr.rkt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,11 @@
313313
cm2))])])]
314314
[(PStruct n ps)
315315
(match (compile-struct-patterns ps (cons #f cm) next 1)
316-
[(list i f cm)
316+
[(list i f cm1)
317317
(let ((fail (gensym)))
318318
(list
319-
(seq (Mov r8 rax)
319+
(seq (%%% "struct")
320+
(Mov r8 rax)
320321
(And r8 ptr-mask)
321322
(Cmp r8 type-struct)
322323
(Jne fail)
@@ -331,7 +332,7 @@
331332
(Label fail)
332333
(Add rsp (* 8 (length cm)))
333334
(Jmp next))
334-
cm))])]))
335+
cm1))])]))
335336

336337
;; [Listof Pat] CEnv Symbol Nat -> (list Asm Asm CEnv)
337338
(define (compile-struct-patterns ps cm next i)

langs/neerdowell/test/test-runner.rkt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,13 @@
428428
#f)
429429
(check-equal? (run '(struct foo (x))
430430
'(foo-x #t))
431-
'err))
431+
'err)
432+
(check-equal? (run '(struct foo (x))
433+
'(struct bar (y))
434+
'(match (bar 5)
435+
[(foo x) #f]
436+
[(bar x) x]))
437+
5))
432438

433439
(define (test-runner-io run)
434440
;; Evildoer examples

0 commit comments

Comments
 (0)