Repository navigation
Description
Summary
Each script below is valid v6 and differs from a control that builds in one place. All seven keep a drawing handle (line, box, label, polyline) or an array in a UDT field, pass a handle through a user function, or declare one as a local. Codegen 1.12.0 translates each of them, and the generated C++ does not compile.
| # | Group | Form | C++ error |
|---|---|---|---|
| 1 | A | h.ln := na on a line ln field (the same with a box and with a label field) |
no viable overloaded '=' on _pf_udt_Holder.get(h).ln = na<double>(); |
| 2 | A | an array<float> xs = na field default, used by Bag.new() |
no viable conversion from 'double' to 'std::vector<double>' on .xs = na<double>() |
| 3 | B | a UDT field passed to a box parameter: extend(h.bx) with extend(box b) => box.set_right(b, bar_index) |
binding reference of type 'Box' to value of type 'const Box' drops 'const' qualifier |
| 4 | B | an untyped local initialised from a label parameter (newLb = lb) and returned in a tuple [newLb, bar_index] |
no viable conversion from returned value of type 'tuple<__unwrap_ref_decay_t<Label &>, [...]>' to function return type 'tuple<Label &, [...]>' |
| 5 | B | a label taken from a tuple ([l2, b2] = mark(...)) assigned to a var label with cur := l2 |
cannot convert 'Label' to 'double' without a conversion operator |
| 6 | C | a local holding an element of an array<polyline>: polyline old = done.shift() (the untyped old = done.shift() too) |
unknown type name 'polyline' on the generated member polyline old = polyline{};, then every member of the generated class fails |
| 7 | C | a UDT field polyline pl = na, assigned with h.pl := polyline.new(pts) |
field designator 'pl' does not refer to any field in type '_PFUdtRecord_Holder' |
A. A bare na for a UDT field of a reference type (cases 1 and 2). A UDT field of type line, box, label or array<float> can hold na in Pine v6. Codegen emits the na for such a field as the numeric na<double>(), which C++ cannot assign to the field's handle or vector type. Writing line(na) instead of na in case 1 builds (since #295 case 4), and leaving out the = na default in case 2 builds, so the forms differ only in how the bare na is typed against the field.
B. A box or label handle crossing a user function boundary (cases 3 to 5). In case 3 the field is read through the const accessor (_pf_udt_Holder.read(h).bx) and bound to the function's Box& parameter. In case 4 the function is declared std::tuple<Label&, int> mark(Label& lb, bool cond): the untyped local takes the reference type of the parameter into the tuple. In case 5 the assignment goes through the numeric wrapper used for double targets.
C. polyline as a declared type (cases 6 and 7). The engine's coverage table (docs/pine_v6_coverage_detail.md) lists the polyline type and polyline.new() / polyline.delete() as parse-and-skip: the drawing has no runtime, and a strategy that only draws it still compiles and runs. That holds for polyline.new(...) as a statement, for var polyline p = na, for array<polyline> and for polyline.delete(done.shift()). It does not hold for a local that takes an array element, nor for a UDT field: the same UDT with a line field builds and runs, and polyline is the type still dropped from the record and from local declarations. Case 7 is the field error that pineforge-4pass/pineforge-engine#17 (closed) described for drawing-typed UDT fields.
Versions
pineforge-codegen 1.12.0 with pineforge-engine v1.12.0 (6e27d0f2). Apple clang 17.0.0, macOS 15.8 arm64. BTCUSDT 1h bars from 2024-01-01 to 2024-03-01 (1,441 bars), initial capital 10000, no commission or slippage.
TradingView: BINANCE:BTCUSDT, 1h, Deep Backtesting over the same dates, measured on 2026-11-14: the seven scripts and their controls save without error and give the same 26 trades (the last one still open at the end of the range), net profit 29.93, as the controls on PineForge.
Reproduction
Every control builds and runs on PineForge with 26 trades and net profit 29.93.
1. na assigned to a line field
//@version=6
strategy("na assigned to a line field", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
type Holder
line ln = na
var h = Holder.new()
if barstate.islast
h.ln := line.new(bar_index - 1, low, bar_index, high)
if barstate.isfirst
h.ln := na
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
strategy.close("Long")
error: no viable overloaded '='
_pf_udt_Holder.get(h).ln = na<double>();
Control, one change: h.ln := line(na). With a box bx or a label lb field in place of the line field, the assignment is emitted the same way (... = na<double>();) and gives the same error.
2. na as the default of an array field
//@version=6
strategy("array field with an na default", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
type Bag
int n = 0
array<float> xs = na
var bag = Bag.new()
if barstate.isfirst
bag.xs := array.new<float>()
bag.xs.push(close)
plot(bag.xs.size())
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
strategy.close("Long")
error: no viable conversion from 'double' to 'std::vector<double>'
Control, one change: array<float> xs with no default.
3. UDT field passed to a box parameter
//@version=6
strategy("box field passed to a box parameter", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
type Holder
box bx = na
extend(box b) =>
box.set_right(b, bar_index)
var h = Holder.new()
if barstate.isfirst
h.bx := box.new(bar_index, high, bar_index, low)
extend(h.bx)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
strategy.close("Long")
error: binding reference of type 'Box' to value of type 'const Box' drops 'const' qualifier
Control, one change: b = h.bx then extend(b).
4. Untyped alias of a label parameter returned in a tuple
//@version=6
strategy("label alias returned in a tuple", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
mark(label lb, bool cond) =>
newLb = lb
if cond
newLb := label.new(bar_index, high, "x")
[newLb, bar_index]
var label cur = na
[l2, b2] = mark(cur, ta.crossover(fast, slow))
label.set_text(l2, "y")
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
strategy.close("Long")
error: no viable conversion from returned value of type 'tuple<__unwrap_ref_decay_t<Label &>, [...]>' to function return type 'tuple<Label &, [...]>'
return std::make_tuple(newLb, pine_bar_index());
Control, one change: label newLb = lb. An untyped parameter (mark(lb, bool cond)) gives the same error.
5. label from a tuple assigned back with :=
//@version=6
strategy("label from a tuple reassigned", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
mark(label lb, bool cond) =>
label newLb = lb
if cond
newLb := label.new(bar_index, high, "x")
[newLb, bar_index]
var label cur = na
[l2, b2] = mark(cur, ta.crossover(fast, slow))
cur := l2
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
strategy.close("Long")
error: cannot convert 'Label' to 'double' without a conversion operator
Control: the function returns newLb alone and the call is l2 = mark(cur, ta.crossover(fast, slow)).
6. polyline local holding an array element
//@version=6
strategy("polyline typed local", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
var array<polyline> done = array.new<polyline>()
if barstate.islast
pts = array.from(chart.point.from_index(bar_index - 5, low), chart.point.from_index(bar_index, high))
done.push(polyline.new(pts))
if done.size() > 3
polyline old = done.shift()
old.delete()
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
strategy.close("Long")
error: unknown type name 'polyline'
polyline old = polyline{};
Control, one change: the two lines polyline old = done.shift() and old.delete() become polyline.delete(done.shift()). Without the type keyword (old = done.shift()) the error is the same; with done.shift().delete() it is use of undeclared identifier 'None'.
7. polyline UDT field
//@version=6
strategy("polyline UDT field", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
type Holder
polyline pl = na
var h = Holder.new()
if barstate.islast
pts = array.from(chart.point.from_index(bar_index - 5, low), chart.point.from_index(bar_index, high))
h.pl := polyline.new(pts)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
strategy.close("Long")
error: field designator 'pl' does not refer to any field in type '_PFUdtRecord_Holder'
error: use of undeclared identifier 'None'
Control: the same holder with a line pl = na field assigned from line.new(bar_index - 5, low, bar_index, high).
Expected
All seven build and run as their controls:
- A: a bare
naassigned to, or used as the default of, a field whose type is a drawing or a collection takes that field's type, as it does withline(na)and with no default. - B: a field read can be passed to a drawing parameter, a tuple returns drawing handles by value whatever the local's declaration, and a drawing taken from a tuple can be assigned to a drawing variable.
- C:
polylineis kept as a no-op handle the waypolyline.new()already is: a local that holds one, the method form ofdelete(), and a UDT field of that type that can be assigned, read and deleted.
Workaround
- A: write the cast form (
line(na),box(na),label(na)) when clearing a drawing field, and leave collection fields without an= nadefault. - B: copy the field into a local before the call (case 3), give the local its type (case 4), and return the handle alone instead of in a tuple (case 5).
- C: delete array elements with
polyline.delete(done.shift())instead of keeping them in a local, and keep polylines in a separatearray<polyline>rather than in a UDT field.
Activity
luisleo526 commentedon Nov 14, 2026
Thank you for the detailed report and the controls; they make each case easy to reproduce.
We will reproduce the seven forms in your table on Codegen 1.12.0 and on current main, find where the translation goes wrong, and post the findings here by 2026-11-15, with a fix target.
🤖 Generated with Claude Code
luisleo526 commentedon Nov 15, 2026
Findings 2026-11-15 (UTC+8), as promised.
nain a UDT field of a reference type, drawing handles passed through or returned from user functions, andpolylineused as a declared type.Fix target: we cannot give one honestly yet, because the remaining verification run has not started (it is scheduled on a cloud machine today), and the fix is not in today's batch. We will post the date here as soon as that run has finished, and the merge commit when it lands.
luisleo526 commentedon Nov 15, 2026
Fixed on main in 0ba632a (#405). Assigning
nato a drawing or array field, passing a drawing handle through a user function or tuple, and keeping a polyline handle in a local or UDT field now generate C++ that compiles. The reproduction tests intests/test_reference_handle_lowering.pyfail on the previous main and pass now.