Skip to content

Strange bug with closures #204

@dstelzer

Description

@dstelzer

https://intfiction.org/t/dialog-wishlist/70278/394?u=draconis

This code:

(program entry point)
	(temp 1)

(temp 1)
	(show [ {A} {B} {C} ])

(show $X) $X

Should produce:

[[0] [1] [2]]

But instead produces:

[[0] [[[2]]] [2]]

Every element of this program seems to be necessary: the bug does not happen if the calls to (temp $) or (show $) are inlined, or if (temp $) does not have a parameter.

Happens on all backends, including debugger.

This is the IR being produced:

Intermediate code for (temp $): 0 -1
R0: (group leader) (1 incoming) clause 65535
	JUMP                      R1           -            -           
R1: (part of group R0) (1 incoming) clause 65535
	ALLOCATE                  0            1            -           
	UNIFY                     A0           1            -           
	TRACEPOINT 0              closurebug.dg:4
	MAKE_PAIR_VV              X0           2            []          
	MAKE_PAIR_VV              A0           X0           []          
	MAKE_PAIR_VV              X1           A0           []          
	MAKE_PAIR_VV              A0           X1           A0          
	MAKE_PAIR_VV              X2           0            []          
	MAKE_PAIR_VV              A0           X2           A0          
	TRACEPOINT 1              closurebug.dg:5
	SET_CONT                  R2           -            -           
	INVOKE_ONCE               (show $)
R2: (group leader) (1 incoming) clause 65535
	TRACEPOINT 3              closurebug.dg:5
	DEALLOCATE 1              -            -            -           
	PROCEED 0                 -            -            -

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions