I found an error similar to others before ([1]) that is still persists as of head right now (0bcb3ca3b9).
CREATE TABLE t (
n INTEGER
);
SELECT *
FROM (VALUES (1)) t(c)
LEFT JOIN t ljl1 ON true
LEFT JOIN LATERAL (WITH cte AS (SELECT * FROM t WHERE t.n = ljl1.n) SELECT * FROM cte) ljl2 ON ljl1.n = 1;
ERROR: wrong varnullingrels (b 3) (expected (b)) for Var 2/1
Note that the error does **not** occur if the CTE is unwrapped like this:
SELECT *
FROM (VALUES (1)) t(c)
LEFT JOIN t ljl1 ON true
LEFT JOIN LATERAL (SELECT * FROM t WHERE t.n = ljl1.n) ljl2 ON ljl1.n = 1;
-markus
[1] https://www.postgresql.org/message-id/CAHewXNnu7u1aT==WjnCRa+SzKb6s80hvwPP_9eMvvvtdyFdqjw@mail.gmail.com